diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-04-04 15:46:39 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-04-04 15:46:39 -0400 |
| commit | 2cee451d5309eb3d0099b4d14e45248054efd834 (patch) | |
| tree | c439aa537c08c7aa65e46d96d3417e7c37027007 | |
| parent | 267ab668915933f170a6255f60cfc0bb0713391a (diff) | |
tuning swipe
| -rw-r--r-- | public/assets/js/lib/Scroller.js | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/public/assets/js/lib/Scroller.js b/public/assets/js/lib/Scroller.js index 4b4c95b..b88ec0f 100644 --- a/public/assets/js/lib/Scroller.js +++ b/public/assets/js/lib/Scroller.js @@ -21,14 +21,19 @@ var Scroller = (function(){ } } - var touching = false, touchStartTime, touchStartY, touchEndY, touchDist, touchScrollTop + var touching = false, touchStartTime + var touchStartY, touchEndY, touchDistY, touchAbsY + var touchStartX, touchEndX, touchDistX, touchAbsX var touchAdvanceDistance = 60 var touchFadeDistance = 60 + var touchGalleryScrubDistance = 100 var $items = $("#items")[0] function touchstart (e) { touching = true touchStartTime = +(new Date) touchStartY = touchEndY = e.touches ? e.touches[0].pageY : e.pageY + touchStartX = touchEndX = e.touches ? e.touches[0].pageX : e.pageX + touchDistY = touchDistX = 0 // $items.className = "no-tween" } function touchmove (e) { @@ -37,15 +42,13 @@ var Scroller = (function(){ var timestamp = +(new Date) var duration = timestamp - touchStartTime touchEndY = e.touches ? e.touches[0].pageY : e.pageY - touchDist = touchStartY - touchEndY - var touchAbs = Math.abs(touchDist) - if (touchAbs > touchAdvanceDistance) { -// touchend(e) - // touchAbs -= 9 - // $items.style.opacity = clamp(1-touchAbs / (touchFadeDistance * 2), 0, 1) - // touchAbs *= -sign(touchDist) - // touchAbs /= 2 - // $items.style[transformProp] = "translateZ(0) translateY(" + touchAbs + "px)" + touchEndX = e.touches ? e.touches[0].pageX : e.pageX + touchDistY = touchStartY - touchEndY + touchDistX = touchStartX - touchEndX + touchAbsY = Math.abs(touchDistY) + touchAbsX = Math.abs(touchDistX) + if (touchAbsY > touchAdvanceDistance && touchAbsX < touchGalleryScrubDistance) { + touchend(e) } } function touchend (e) { @@ -54,10 +57,15 @@ var Scroller = (function(){ touching = false var timestamp = +(new Date) var duration = timestamp - touchStartTime - touchDist = touchStartY - touchEndY - console.log("DURATION >>", duration, touchDist) - if ( (duration < 120 && Math.abs(touchDist) < 10) || Math.abs(touchDist) >= touchAdvanceDistance) { - touchDist > 0 ? step(1) : step(-1) + + console.log("DURATION >>", duration, touchDistY, touchDistX) + + if (touchAbsX > touchGalleryScrubDistance) { + return + } + + if ( (duration < 120 && touchAbsY < 10) || touchAbsY >= touchAdvanceDistance) { + touchDistY > 0 ? step(1) : step(-1) } // $items.className = "" |
