Skip to content

Instantly share code, notes, and snippets.

@thinkadoo
Forked from jonhoo/gist:2205417
Created February 7, 2013 21:30
Show Gist options
  • Save thinkadoo/4734444 to your computer and use it in GitHub Desktop.
Save thinkadoo/4734444 to your computer and use it in GitHub Desktop.
try{
document.createEvent("TouchEvent");
// Here we're ensured touch capabilities
var scroll = document.getElementById('myid');
var start = null;
var clickIfEnd = true;
scroll.addEventListener('touchstart', function (e) {
start = e.touches[0].pageX;
clickIfEnd = true;
e.preventDefault();
}, false);
scroll.addEventListener('touchmove', function (e) {
this.scrollLeft = start - e.touches[0].pageX;
clickIfEnd = false;
e.preventDefault();
}, false);
scroll.addEventListener('touchend', function (e) {
if (clickIfEnd) {
if (e) {
clickIfEnd = e.target;
// Add a delay before treating this as a click, in case it was accidental
setTimeout(arguments.callee, 100);
} else {
// clickIfEnd is the element that was clicked!
}
}
}, false);
} catch(e){}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment