问题
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