Last active
March 13, 2017 11:58
-
-
Save gustaflindqvist/c1975f268427dc0736b3c37e40fe155c 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
<div id="scroller" style="width: 50%; overflow: auto;"> | |
<iframe height="100%" id="iframe" scrolling="no" width="100%" id="iframe" src="responses.html" /> | |
</div> |
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