Chrome 中在文本区域上执行鼠标悬停的奇怪行为

发布于 2024-11-02 14:53:27 字数 401 浏览 1 评论 0原文

我有一个奇怪的问题,我无法解决。它仅存在于 Chrome 中。我使用的库是 Prototype 1.6。

基本上,我将两个元素包装到一个容器元素中。两个子元素中的第一个是可见的,第二个是隐藏的。在隐藏元素内我有一个 textarea 元素。当我将鼠标悬停在容器元素上时,第一个子元素应该隐藏,第二个子元素应该显示出来。当我鼠标移出时,行为应该相反。您可以在这里看到它以及错误:)

http://jsfiddle.net/gmM9m/2

由于某种原因,在 Chrome 中,当我将鼠标悬停在文本区域上时,元素开始闪烁,因为它们不断地自行打开和关闭。有谁知道导致这种行为的原因以及我该如何规避它?

谢谢你! 卢卡

I have a strange problem I can't wrap my head against. It is present only in Chrome. The library I'm using is Prototype 1.6.

Basically, I have two elements wrapped into a container element. First of the two children elements is visible, the second one is hidden. Inside the hidden element I have a textarea element. When I mousover the container element, the first child should hide, second one should show itself. When I mouseout, the behavior should be opposite. You can see it here, along with the bug :)

http://jsfiddle.net/gmM9m/2

For some reason, in Chrome when I mouseover the textarea, the elements start blinking because they constantly turn themselves on and off. Does anyone have any idea what causes this behavior and how can I circumvent it?

Thank you!
Luka

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

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

发布评论

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

评论(3

じее 2024-11-09 14:53:27

我得到的最接近的是将事件添加到鼠标移出的回调函数中,并确保它来自您想要的元素。这看起来有点 hackish,但也许这是 Chrome 中的一个错误。我也看到了,但是wong2似乎没有看到。

查看我的修订版,初始鼠标悬停时仍然有轻微的口吃。

http://jsfiddle.net/gmM9m/10/

The closest I've gotten is adding the event to the callback function for the mouseout and making sure that it's coming from the element you want. It seems kind of hackish, but perhaps it's a bug in Chrome. I'm seeing it as well, but wong2 does not seem to be seeing it.

See my revision, still a slight stutter on initial mouseover.

http://jsfiddle.net/gmM9m/10/

银河中√捞星星 2024-11-09 14:53:27

我刚刚遇到类似的问题并使用 jquery“mouseenter”和“mouseleave”事件解决了它
请参阅 http://api.jquery.com/mouseenter/

I just run into similar problem and solved it with using jquery "mouseenter" and "mouseleave" event
see http://api.jquery.com/mouseenter/

最佳男配角 2024-11-09 14:53:27

这对我有用。(我不熟悉 JQuery 的 observe 方法,所以我使用 JavaScript 的 addEventListener 代替)

$('container').addEventListener("mouseover", function(event){
    $('front').hide();
    $('back').show();
    event.stopPropagation();
}, false);

$('container').addEventListener("mouseout", function(event){
    $('front').show();
    $('back').hide();
    event.stopPropagation();
}, false);

重点是 stopPropagation。在此处运行:http://jsfiddle.net/RDXzR/

This works for me.(I'm not familar with JQuery's observe method, so I use JavaScript's addEventListener instead)

$('container').addEventListener("mouseover", function(event){
    $('front').hide();
    $('back').show();
    event.stopPropagation();
}, false);

$('container').addEventListener("mouseout", function(event){
    $('front').show();
    $('back').hide();
    event.stopPropagation();
}, false);

The point is stopPropagation. Run it here: http://jsfiddle.net/RDXzR/

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