两个 dom 元素上的触摸事件?
我有两个相邻的 dom 元素。
在触摸事件期间,我希望能够在每个元素上滑动。正如我所做的那样,根据我所处的元素,我希望发生不同的事情。
这会是什么样子?
由于触摸已按下,当它们滑动到新元素时,不会触发新的 touchstart 事件。
谢谢!
编辑:这是我想要在每个项目上携带恒定 touchmove 事件的实际代码
ul
li 1
li 2
li 3
,我真正需要它能够知道当前 li 的索引
现在我正在尝试:
$('ul').live 'touchmove', (event) ->
element = document.elementFromPoint(event.clientX, event.clientY)
#now i need the index of this element somehow
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
pageX 和 pageY 不是 clientX 和 clientY
很难研究这些事件对象的触摸事件,因为移动 Safari 控制台非常原始。
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.
您将需要监听“touchmove”事件的触发。然后使用 document.elementFromPoint(event.clientX, event.clientY) 来确定手指位于哪个 div 上。
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.