为什么mousewheel事件的target属性与其他(click,mousedown,touchstart)事件的target属性不同? [英] Why is the target property of the mousewheel event different from that of other (click, mousedown, touchstart) events?

查看:109
本文介绍了为什么mousewheel事件的target属性与其他(click,mousedown,touchstart)事件的target属性不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mousewheel事件的 target 属性提供了在操作mousewheel(或支持手势的触摸板)时鼠标当前悬停的DOM元素。

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.

这样做(至少在Safari 6中,我将在以后测试其他浏览器)将文本节点本身作为 target

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.

这是否有原因?我希望避免检查父节点,尽管值得庆幸的是,我只需要检查 target 节点的父节点。

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.

推荐答案

这是一个jQuery代码的片段,在该片段中,该行为得到了规范因为是个错误:

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;
}

这篇关于为什么mousewheel事件的target属性与其他(click,mousedown,touchstart)事件的target属性不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆