admin管理员组文章数量:1201373
Basically we've got a listener on "DOMMouseScroll" that returns the delta on the mouse scroll and in turn use this data to move div elements on our page.
We want to add this functionality to the iPad but are struggling to work out what listeners, are needed to return a touch scroll delta value.
Anyone have any suggestions, or places to start?
Cheers - C
Basically we've got a listener on "DOMMouseScroll" that returns the delta on the mouse scroll and in turn use this data to move div elements on our page.
We want to add this functionality to the iPad but are struggling to work out what listeners, are needed to return a touch scroll delta value.
Anyone have any suggestions, or places to start?
Cheers - C
Share Improve this question asked Jan 19, 2012 at 10:58 Caius EugeneCaius Eugene 8554 gold badges14 silver badges26 bronze badges2 Answers
Reset to default 23There is no "delta" but you do have access to X
and Y
.
This mean you can write some code to fire on touch move and calculate the "delta":
element.addEventListener("touchstart", touchStart, false);
element.addEventListener("touchmove", touchMove, false);
var start = {x:0, y:0};
function touchStart(event) {
start.x = event.touches[0].pageX;
start.y = event.touches[0].pageY;
}
function touchMove(event) {
offset = {};
offset.x = start.x - event.touches[0].pageX;
offset.y = start.y - event.touches[0].pageY;
return offset;
}
Further reference: http://developer.apple.com/library/safari/#documentation/appleapplications/reference/safariwebcontent/HandlingEvents/HandlingEvents.html
In case that you don't want realtime delta
, only press & realease
delta you can use:
- touchstart
- touchend
- TouchEvent.changedTouches
Based on @samccone code.
element.addEventListener("touchstart", touchStart, false);
element.addEventListener("touchend", touchEnd, false);
var start = {x:0, y:0};
function touchStart(event) {
start.x = event.changedTouches[0].pageX;
start.y = event.changedTouches[0].pageY;
}
function touchEnd(event) {
offset = {};
offset.x = start.x - event.changedTouches[0].pageX;
offset.y = start.y - event.changedTouches[0].pageY;
return offset;
}
本文标签: javascripttouch scroll delta value on iPadStack Overflow
版权声明:本文标题:javascript - touch scroll delta value on iPad - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738632796a2103849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论