-
-
Save Drvanon/5867343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isTouchDevice(){ | |
try{ | |
document.createEvent("TouchEvent"); | |
return true; | |
}catch(e){ | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function touchScroll(id){ | |
if(isTouchDevice()){ //if touch events exist... | |
var el=document.getElementById(id); | |
var scrollStartPos=0; | |
document.getElementById(id).addEventListener("touchstart", function(event) { | |
scrollStartPos=this.scrollTop+event.touches[0].pageY; | |
event.preventDefault(); | |
},false); | |
document.getElementById(id).addEventListener("touchmove", function(event) { | |
this.scrollTop=scrollStartPos-event.touches[0].pageY; | |
event.preventDefault(); | |
},false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment