Why is the target property of the mousewheel event different from that of other (click, mousedown, touchstart) events?

与世无争的帅哥 提交于 2020-01-13 09:09:11

问题


The mousewheel event's target property provides the DOM element that the mouse is currently hovering over as the mousewheel (or gesture-capable touchpad) is being operated.

When I do this (at least in Safari 6, I will test other browsers later) I will get the text node itself as target.

This never happens with other events which always produce a non text node even if I perform the action directly over text.

Needless to say it makes the code more complex than otherwise.

Is there a reason for this? I'd like to avoid having to check the parent node, though thankfully the nice thing about this situation is that I would only ever need to check the target node's parent.

I can't decide if this is a feature or a bug.


回答1:


Here's a snippet of the jQuery code where they normalize this behaviour because it's a bug:

// Target should not be a text node (#504, Safari)
if ( event.target.nodeType === 3 ) {
    event.target = event.target.parentNode;
}


来源:https://stackoverflow.com/questions/14109763/why-is-the-target-property-of-the-mousewheel-event-different-from-that-of-other

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