Skip to content

Instantly share code, notes, and snippets.

@gustaflindqvist

gustaflindqvist/index.html

Last active Mar 13, 2017
Embed
What would you like to do?
Solve touch position and works great inside iframes
<div id="scroller" style="width: 50%; overflow: auto;">
<iframe height="100%" id="iframe" scrolling="no" width="100%" id="iframe" src="responses.html" />
</div>
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