Skip to content

Commit

Permalink
Correct swiping behavior - #321
Browse files Browse the repository at this point in the history
- Add threshold option (this removes the need for jquery.swipe)

Signed-off-by: Robert Weber <[email protected]>
  • Loading branch information
rodebert committed Feb 5, 2016
1 parent 46b1ce7 commit 95f5de0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 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.

18 changes: 14 additions & 4 deletions src/js/unslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@
// Have swipe support?
// You can set this here with a boolean and always use
// initSwipe/destroySwipe later on.
swipe: true
swipe: true,
// Swipe threshold -
// lower float for enabling short swipe
swipeThreshold: 0.2
};

// Set defaults
Expand Down Expand Up @@ -311,10 +314,17 @@
},

moveend: function(e) {

if((Math.abs(e.distX) / width) < $.event.special.swipe.settings.threshold) {
// Check if swiped distance is greater than threshold.
// If yes slide to next/prev slide. If not animate to
// starting point.

self[ e.distX < 0 ? 'next' : 'prev' ]();
if((Math.abs(e.distX) / width) > self.options.swipeThreshold) {

self[e.distX < 0 ? 'next' : 'prev']();
}
else {

self.$container.animate({left: -(100 * self.current) + '%' }, self.options.speed / 2 );
}
}
});
Expand Down

0 comments on commit 95f5de0

Please sign in to comment.