From b84788826f4b2f6193c4901633d9da195dd61e72 Mon Sep 17 00:00:00 2001 From: Sean Clark Date: Tue, 29 Apr 2014 12:46:18 -0400 Subject: [PATCH 1/3] 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. --- js/sliders.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/js/sliders.js b/js/sliders.js index c42577e..bfd2a61 100644 --- a/js/sliders.js +++ b/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 From 5f426dac27b35364d02c1ef925b00c596960d517 Mon Sep 17 00:00:00 2001 From: Sean Clark Date: Tue, 29 Apr 2014 18:20:32 -0400 Subject: [PATCH 2/3] Update sliders.js Fixed coding style errors --- js/sliders.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/js/sliders.js b/js/sliders.js index bfd2a61..5e183c1 100644 --- a/js/sliders.js +++ b/js/sliders.js @@ -83,9 +83,9 @@ 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) { + if (!startedMoving) { pageX += (e.touches[0].pageX - pageX) - 1; } @@ -96,7 +96,7 @@ if (typeof isScrolling === 'undefined' && startedMoving) { isScrolling = Math.abs(deltaY) > Math.abs(deltaX); - } + } if (isScrolling) { return; @@ -110,7 +110,7 @@ slideNumber === lastSlide && deltaX < 0 ? (Math.abs(pageX) / sliderWidth) + 1.25 : 1; slider.style.webkitTransform = 'translate3d(' + offsetX + 'px,0,0)'; - + // started moving startedMoving = true; }; @@ -119,7 +119,7 @@ if (!slider || isScrolling) { return; } - + // were done moving startedMoving = false; From ef685cdec719e06c62ba01dfbce5f5c4b647af70 Mon Sep 17 00:00:00 2001 From: Sean Clark Date: Tue, 29 Apr 2014 21:18:46 -0400 Subject: [PATCH 3/3] Update sliders.js grammar --- js/sliders.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/sliders.js b/js/sliders.js index 5e183c1..e8bdf73 100644 --- a/js/sliders.js +++ b/js/sliders.js @@ -120,7 +120,7 @@ return; } - // were done moving + // we're done moving startedMoving = false; setSlideNumber(