From d63892b54a85e00bb73ce248f8db29acf327d293 Mon Sep 17 00:00:00 2001 From: Tero Piirainen Date: Mon, 20 Sep 2010 12:34:56 +0000 Subject: [PATCH] ability to seek scrollable with iPod/iPhone touch event --- src/rangeinput/rangeinput.js | 2 +- src/scrollable/scrollable.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/rangeinput/rangeinput.js b/src/rangeinput/rangeinput.js index 9307af6..e63533a 100644 --- a/src/rangeinput/rangeinput.js +++ b/src/rangeinput/rangeinput.js @@ -371,7 +371,7 @@ if (input.is(":disabled") || e.target == handle[0]) { return e.preventDefault(); } - + init(); var fix = handle.width() / 2; slide(e, vertical ? len-origo-fix + e.pageY : e.pageX -origo -fix); }); diff --git a/src/scrollable/scrollable.js b/src/scrollable/scrollable.js index 75917a3..2a73119 100644 --- a/src/scrollable/scrollable.js +++ b/src/scrollable/scrollable.js @@ -31,6 +31,7 @@ prev: '.prev', speed: 400, vertical: false, + touch: true, wheelSpeed: 0 } }; @@ -256,6 +257,30 @@ }); } + // touch event + if (conf.touch) { + var touch = {}; + + itemWrap[0].ontouchstart = function(e) { + var t = e.touches[0]; + touch.x = t.clientX; + touch.y = t.clientY; + }; + + itemWrap[0].ontouchmove = function(e) { + + // only deal with one finger + if (e.touches.length == 1 && !itemWrap.is(":animated")) { + var t = e.touches[0], + deltaX = touch.x - t.clientX, + deltaY = touch.y - t.clientY; + + self[vertical && deltaY > 0 || !vertical && deltaX > 0 ? 'next' : 'prev'](); + e.preventDefault(); + } + }; + } + if (conf.keyboard) { $(document).bind("keydown.scrollable", function(evt) {