Touch events over two dom elements?

我是研究僧i 提交于 2019-12-14 03:57:29

问题


I have two dom elements right next to one another.

During a touch event I want to be able to slide over each element. As I do, depending on what element i'm on I want different things to happen.

What would this look like?

Since the touch is down a new touchstart event doesn't fire as they slide to the new element.

Thanks!

EDIT: this is the actual code

ul
   li 1
   li 2
   li 3

I want to carry a constant touchmove event over each item and all i really need it to be able to know the index of the current li

Right now I'm trying:

$('ul').live 'touchmove', (event) ->
   element = document.elementFromPoint(event.clientX, event.clientY)
   #now i need the index of this element somehow

回答1:


element = document.elementFromPoint(event.pageX, event.pageY)

pageX and pageY not clientX and clientY

It's hard to look into these event objects for touch events because the mobile Safari console is so freaking primitive.




回答2:


You're going to want to listen for the "touchmove" event to be triggered. Then use document.elementFromPoint(event.clientX, event.clientY) to figure out which div the finger is over.



来源:https://stackoverflow.com/questions/7814550/touch-events-over-two-dom-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!