Internet Explorer:当目标 DOM 元素在 DOM 中移动时,悬停状态会变得粘滞

发布于 2024-12-12 00:30:32 字数 653 浏览 0 评论 0原文

我正在构建一个应用程序,允许您只需单击列表项即可将列表项从一个列表移动到另一个列表。然而,为了让用户知道 clik 的预期操作是什么,我在 CSS 中设置了一个 :hover 状态,它显示诸如“<< move”之类的指令。

但是我发现的问题是, Internet Explorer(测试版本 7-9),当我移动 DOM 元素时,即使鼠标四处移动,该元素的 :hover 状态仍然保持(变得粘滞)。仅当用户将鼠标悬停在新位置的项目上然后将鼠标移开时,:hover 状态才会消失。这似乎是 Internet Explorer 特有的问题。

如果您使用 IE,则可以通过访问 http://jsfiddle.net/hc2Eu/32/ 查看

问题当然,一种解决方法是不使用 CSS :hover 状态并使用 JQuery 悬停事件,但这肯定不是最好的方法,并且在 CSS 中控制元素 :hover 状态是迄今为止最强大的方法做事的方式 这。解决方法可以在 http://jsfiddle.net/hc2Eu/29/

有谁知道我如何告诉互联网资源管理器不知何故发现某个元素不再位于鼠标下方,并且它应该释放 :hover 状态?

马特

I am building an app that allows you to move list items from one list to another by simply clicking on them. However, in order for the user to know what the intended action for a clik is, I set up a :hover state in the CSS which shows an instruction such as "<< move"

The problem I have found however is that in Internet Explorer (tested versions 7-9), when I move a DOM element the :hover state of that element remains (becomes sticky), even when the mouse is moved around. The :hover state only disappears when a user hovers over the item in it's new location and then moves their mouse away. This is an Internet Explorer only issue it seems.

You can see the problem if you are using IE by going to http://jsfiddle.net/hc2Eu/32/

There is of course a workaround which is to not use CSS :hover state and use a JQuery hover event instead, but this is certainly not the best way of doing things, and keeping elements :hover state controlled in CSS is by far and away the most robust way of doing this. The workaround can be seen at http://jsfiddle.net/hc2Eu/29/

Has anyone figured out how I can tell Internet Explorer somehow that an element is no longer under the mouse, and it should release the :hover state?

Matt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倦话 2024-12-19 00:30:33

这将解决你的问题。克隆单击的项目(如果要保存单击事件和其他处理程序,请添加 true)将其插入到其自身之后,以便它在 dom 中具有相同的位置。然后将其删除。克隆不会卡在悬停状态。所有引用都是相对的(this),因此它可以在任何地方工作而无需更改选择器。

        $("#elementwithhover").click(function() { 
            // code that makes element or parent slide or 
            // otherwise move out from under mouse. 
            $(this).clone(true).insertAfter($(this));
            $(this).remove();
        });

this will handle your issue. clone the clicked item(add true if you want to save click event and other handlers) insert it after itself so it has the same place in the dom. then remove it. the clone will not be stuck with the hover state stuck. All references are relative (this) so it'll work anywhere without changing selectors.

        $("#elementwithhover").click(function() { 
            // code that makes element or parent slide or 
            // otherwise move out from under mouse. 
            $(this).clone(true).insertAfter($(this));
            $(this).remove();
        });
宫墨修音 2024-12-19 00:30:32

尝试克隆该元素而不是直接附加它。当您追加时,您将从 DOM 中的当前位置和状态获取元素并将其放置在新位置 - 基本上只是移动它。发生这种情况时,IE 显然不会重新绘制元素,也不会重置其状态,直到鼠标悬停为止。

通过克隆它,您可以强制 IE 创建一个新元素,由于该元素不在页面上,因此无论如何都无法对其应用悬停状态。然后只需将其附加到新容器中,删除原始容器即可。

请参阅此小提琴中的示例:两行代码,跨浏览器,您将保持简洁并且不会污染您的代码。 :)

http://jsfiddle.net/hc2Eu/36/

Try cloning the element instead of appending it directly. When you append, you're taking the element from it's current position and state in the DOM and placing it in its new position - basically just moving it. IE is clearly not repainting the element when this happens, or resetting its state until you mouseover.

By cloning it, you force IE to create a new element, which, since it's not on the page, can't have the hover state applied to it anyway. Then just append it in its new container, remove the original, and you're done.

See an example in this fiddle: Two lines of code, cross-browser, and you'll remain concise and not pollute your code. :)

http://jsfiddle.net/hc2Eu/36/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文