summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/Scroller.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js/lib/Scroller.js')
-rw-r--r--public/assets/js/lib/Scroller.js55
1 files changed, 44 insertions, 11 deletions
diff --git a/public/assets/js/lib/Scroller.js b/public/assets/js/lib/Scroller.js
index 3bebce7..b88ec0f 100644
--- a/public/assets/js/lib/Scroller.js
+++ b/public/assets/js/lib/Scroller.js
@@ -11,9 +11,9 @@ var Scroller = (function(){
left = opt.left
right = opt.right
if (is_mobile) {
-// document.body.addEventListener("touchstart", touchstart)
-// document.body.addEventListener("touchmove", touchmove)
-// document.body.addEventListener("touchend", touchend)
+ document.body.addEventListener("touchstart", touchstart)
+ document.body.addEventListener("touchmove", touchmove)
+ document.body.addEventListener("touchend", touchend)
}
else {
document.body.addEventListener("wheel", wheelDelta)
@@ -21,11 +21,20 @@ 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) {
if (! touching) return
@@ -33,7 +42,14 @@ var Scroller = (function(){
var timestamp = +(new Date)
var duration = timestamp - touchStartTime
touchEndY = e.touches ? e.touches[0].pageY : e.pageY
- touchDist = touchStartY - touchEndY
+ 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) {
if (! touching) return
@@ -41,13 +57,30 @@ var Scroller = (function(){
touching = false
var timestamp = +(new Date)
var duration = timestamp - touchStartTime
- touchDist = touchStartY - touchEndY
- if (Math.abs(touchDist) < 10 || duration < 100) {
- step(1)
- }
- else {
- 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 = ""
+// setTimeout(function(){
+// $items.style[transformProp] = "translateZ(0) translateY(0)"
+// if (Math.abs(touchDist) >= touchAdvanceDistance) {
+// $items.style.opacity = 0
+// setTimeout(function(){
+// $items.style.opacity = 1
+// }, 200)
+// }
+// else {
+// $items.style.opacity = 1
+// }
+// }, 0)
}
function wheelDelta (e){