Skip to content

Commit d63892b

Browse files
committed
ability to seek scrollable with iPod/iPhone touch event
1 parent b3e9d79 commit d63892b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/rangeinput/rangeinput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@
371371
if (input.is(":disabled") || e.target == handle[0]) {
372372
return e.preventDefault();
373373
}
374-
374+
init();
375375
var fix = handle.width() / 2;
376376
slide(e, vertical ? len-origo-fix + e.pageY : e.pageX -origo -fix);
377377
});

src/scrollable/scrollable.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
prev: '.prev',
3232
speed: 400,
3333
vertical: false,
34+
touch: true,
3435
wheelSpeed: 0
3536
}
3637
};
@@ -256,6 +257,30 @@
256257
});
257258
}
258259

260+
// touch event
261+
if (conf.touch) {
262+
var touch = {};
263+
264+
itemWrap[0].ontouchstart = function(e) {
265+
var t = e.touches[0];
266+
touch.x = t.clientX;
267+
touch.y = t.clientY;
268+
};
269+
270+
itemWrap[0].ontouchmove = function(e) {
271+
272+
// only deal with one finger
273+
if (e.touches.length == 1 && !itemWrap.is(":animated")) {
274+
var t = e.touches[0],
275+
deltaX = touch.x - t.clientX,
276+
deltaY = touch.y - t.clientY;
277+
278+
self[vertical && deltaY > 0 || !vertical && deltaX > 0 ? 'next' : 'prev']();
279+
e.preventDefault();
280+
}
281+
};
282+
}
283+
259284
if (conf.keyboard) {
260285

261286
$(document).bind("keydown.scrollable", function(evt) {

0 commit comments

Comments
 (0)