Skip to content

Commit

Permalink
check slide position and swipe threshold before reverting slide back
Browse files Browse the repository at this point in the history
  • Loading branch information
Visual Idiot committed Nov 20, 2015
1 parent 62b9423 commit e5fb7ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 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.

21 changes: 16 additions & 5 deletions src/js/unslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@
animateHeight: false,

// Active class for the nav
activeClass: self._ + '-active'
activeClass: self._ + '-active',

// Have swipe support?
// You can set this here with a boolean and always use
// initSwipe/destroySwipe later on.
swipe: true
};

// Set defaults
Expand Down Expand Up @@ -130,7 +135,7 @@
});

// Add swipe support
if(typeof jQuery.event.special.swipe !== undefined) {
if(typeof jQuery.event.special.swipe !== undefined && self.options.swipe) {
self.initSwipe();
}

Expand Down Expand Up @@ -297,7 +302,13 @@
if(self.options.animation !== 'fade') {
self.$container.on({
move: function(e) {
self.$container.css('left', (100 * e.distX / width) + '%');
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);
}
}
});
}
Expand Down Expand Up @@ -490,14 +501,14 @@
self._move($active, {opacity: 1}, false);
};

self._move = function($el, obj, callback) {
self._move = function($el, obj, callback, speed) {
if(callback !== false) {
callback = function() {
self.$context.trigger(self._ + '.moved');
};
}

return $el._move(obj, self.options.speed, self.options.easing, callback);
return $el._move(obj, speed || self.options.speed, self.options.easing, callback);
};

// Allow daisy-chaining of methods
Expand Down

0 comments on commit e5fb7ff

Please sign in to comment.