Skip to content

Commit

Permalink
Correct swipe/move handling - fixes #321
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Weber <closingtag@gmail.com>
  • Loading branch information
rodebert committed Jan 14, 2016
1 parent 64a9d89 commit 289cfe2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dist/js/unslider-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 15 additions & 16 deletions src/js/unslider.js
Expand Up @@ -289,33 +289,32 @@
self.initSwipe = function() {
var width = self.$slides.width();

self.$container.on({
swipeleft: self.next,
swiperight: self.prev,

movestart: function(e) {
// If the movestart heads off in a upwards or downwards
// direction, prevent it so that the browser scrolls normally.
if((e.distX > e.distY && e.distX < -e.distY) || (e.distX < e.distY && e.distX > -e.distY)) {
return !!e.preventDefault();
}

self.$container.css('position', 'relative');
}
});

// We don't want to have a tactile swipe in the slider
// in the fade animation, as it can cause some problems
// with layout, so we'll just disable it.
if(self.options.animation !== 'fade') {

self.$container.on({

movestart: function(e) {
// If the movestart heads off in a upwards or downwards
// direction, prevent it so that the browser scrolls normally.
if((e.distX > e.distY && e.distX < -e.distY) || (e.distX < e.distY && e.distX > -e.distY)) {
return !!e.preventDefault();
}

self.$container.css('position', 'relative');
},

move: function(e) {
self.$container.css('left', -(100 * self.current) + (100 * e.distX / width) + '%');
},

moveend: function(e) {

if((Math.abs(e.distX) / width) < $.event.special.swipe.settings.threshold) {
return self._move(self.$container, {left: -(100 * self.current) + '%'}, false, 200);

self[self.current + e.distX < 0 ? 'next' : 'prev']();
}
}
});
Expand Down

0 comments on commit 289cfe2

Please sign in to comment.