Browse Source

Update sliders.js

This update get's rid of the jump at the start of the slide. On almost every slider know to man there is a 15px jump. This one has it to. If you log out deltaX you'll see it almost always starts with -16px. That's a noticeable jump. This change fixes it so that the slide starts from 0 and smoothly goes from there.
pull/573/head
Sean Clark 11 years ago
parent
commit
b84788826f
  1. 16
      js/sliders.js

16
js/sliders.js

@ -23,6 +23,7 @@
var slideNumber;
var isScrolling;
var scrollableArea;
var startedMoving;
var getSlider = function (target) {
var i;
@ -82,15 +83,20 @@
if (e.touches.length > 1 || !slider) {
return; // Exit if a pinch || no slider
}
// adjust the starting position if we just started to avoid jumpage
if(!startedMoving) {
pageX += (e.touches[0].pageX - pageX) - 1;
}
deltaX = e.touches[0].pageX - pageX;
deltaY = e.touches[0].pageY - pageY;
pageX = e.touches[0].pageX;
pageY = e.touches[0].pageY;
if (typeof isScrolling === 'undefined') {
if (typeof isScrolling === 'undefined' && startedMoving) {
isScrolling = Math.abs(deltaY) > Math.abs(deltaX);
}
}
if (isScrolling) {
return;
@ -104,12 +110,18 @@
slideNumber === lastSlide && deltaX < 0 ? (Math.abs(pageX) / sliderWidth) + 1.25 : 1;
slider.style.webkitTransform = 'translate3d(' + offsetX + 'px,0,0)';
// started moving
startedMoving = true;
};
var onTouchEnd = function (e) {
if (!slider || isScrolling) {
return;
}
// were done moving
startedMoving = false;
setSlideNumber(
(+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0

Loading…
Cancel
Save