Created
March 13, 2017 11:57
-
-
Save gustaflindqvist/c5c2d41ba0a41a63309effeee8ab0a15 to your computer and use it in GitHub Desktop.
Solve touch position and works great inside iframes
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
var startY = 0; | |
var startX = 0; | |
document.addEventListener("touchstart", function (event) { | |
alert(11); | |
parent.window.scrollTo(0, 1); | |
startY = event.targetTouches[0].pageY; | |
startX = event.targetTouches[0].pageX; | |
}); | |
document.addEventListener("touchmove", function (event) { | |
event.preventDefault(); | |
var posy = event.targetTouches[0].pageY; | |
var h = parent.document.getElementById("scroller"); | |
var sty = h.scrollTop; | |
var posx = event.targetTouches[0].pageX; | |
var stx = h.scrollLeft; | |
h.scrollTop = sty - (posy - startY); | |
h.scrollLeft = stx - (posx - startX); | |
startY = posy; | |
startX = posx; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment