Skip to content

Commit 9d2a112

Browse files
author
tonybartilorofb
authored
Update inner-slider.js
1 parent 018bcdf commit 9d2a112

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/inner-slider.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export class InnerSlider extends React.Component {
103103
}
104104
if (window.addEventListener) {
105105
window.addEventListener("resize", this.onWindowResized);
106+
window.addEventListener("touchstart", this.touchStart);
107+
window.addEventListener("touchmove", this.preventTouch, {
108+
passive: false
109+
});
106110
} else {
107111
window.attachEvent("onresize", this.onWindowResized);
108112
}
@@ -120,13 +124,37 @@ export class InnerSlider extends React.Component {
120124
}
121125
if (window.addEventListener) {
122126
window.removeEventListener("resize", this.onWindowResized);
127+
window.removeEventListener("touchstart", this.touchStart);
128+
window.removeEventListener("touchmove", this.preventTouch, {
129+
passive: false
130+
});
123131
} else {
124132
window.detachEvent("onresize", this.onWindowResized);
125133
}
126134
if (this.autoplayTimer) {
127135
clearInterval(this.autoplayTimer);
128136
}
129137
};
138+
139+
touchStart(e) {
140+
this.firstClientX = e.touches[0].clientX;
141+
this.firstClientY = e.touches[0].clientY;
142+
}
143+
144+
preventTouch(e) {
145+
const minValue = 5; // threshold
146+
147+
this.clientX = e.touches[0].clientX - this.firstClientX;
148+
this.clientY = e.touches[0].clientY - this.firstClientY;
149+
150+
// Vertical scrolling does not work when you start swiping horizontally.
151+
if (Math.abs(this.clientX) > minValue) {
152+
e.preventDefault();
153+
e.returnValue = false;
154+
return false;
155+
}
156+
}
157+
130158
UNSAFE_componentWillReceiveProps = nextProps => {
131159
let spec = {
132160
listRef: this.list,
@@ -709,7 +737,7 @@ export class InnerSlider extends React.Component {
709737
let innerSliderProps = {
710738
className: className,
711739
dir: "ltr",
712-
style:this.props.style
740+
style: this.props.style
713741
};
714742

715743
if (this.props.unslick) {

0 commit comments

Comments
 (0)