jquery去除闪烁

发布于 2024-09-30 12:48:06 字数 307 浏览 1 评论 0原文

块在 .hover() 上闪烁

这是一个完整示例 - http://jsfiddle.net/xBEjQ/

如何解决这个问题?

UPD:弹出窗口应该在鼠标离开较小的块后被删除 /em> (.image),而不是 .popup 块。

Block is blinking on .hover()

Here is a full example - http://jsfiddle.net/xBEjQ/

How to fix this?

UPD: popup should be removed after the mouse leaved the smaller block (.image), not .popup block.

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

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

发布评论

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

评论(4

兔姬 2024-10-07 12:48:06

对于更新的问题:由于鼠标事件不会发生在较小的元素上(它完全重叠),因此您必须使用第三个​​

; 像这样:

<div class="block">
    <div class="popup"></div>
    <div class="popup upper"></div>
    <div class="image"></div>
</div>

并添加此 CSS(注意比其他 .popup 更高的 z-index):

.upper { width: 100px; height: 100px; z-index: 41; }

和脚本以匹配:

$(".block .image").mouseenter(function(){
    console.log($(this).siblings(".popup").length);
  $(this).siblings(".popup").show();
});
$(".block .upper").mouseleave(function(){
  $(this).siblings(".popup").andSelf().hide();
});

您可以在这里进行测试


对于上一个问题:由于弹出窗口位于元素顶部,因此使用 mouseenter 位于触发器上,mouseleave 位于弹出窗口,如下所示:

$(".block .image").mouseenter(function(){
  $(this).siblings(".popup").show();
});
$(".block .popup").mouseleave(function(){
  $(this).hide();
});

您可以在此处测试

For updated Question: Since the mouse events won't occur on that smaller element (it's completely overlapped) you'd have to use a third <div> like this:

<div class="block">
    <div class="popup"></div>
    <div class="popup upper"></div>
    <div class="image"></div>
</div>

And add this CSS (note the higher z-index than the other .popup):

.upper { width: 100px; height: 100px; z-index: 41; }

and script to match:

$(".block .image").mouseenter(function(){
    console.log($(this).siblings(".popup").length);
  $(this).siblings(".popup").show();
});
$(".block .upper").mouseleave(function(){
  $(this).siblings(".popup").andSelf().hide();
});

You can test it out here.


For previous question: Since the popup is over top of the element, use the mouseenter on the trigger, mouseleave on the popup, like this:

$(".block .image").mouseenter(function(){
  $(this).siblings(".popup").show();
});
$(".block .popup").mouseleave(function(){
  $(this).hide();
});

You can test it here.

风和你 2024-10-07 12:48:06

更新了您的 jsfiddle: http://jsfiddle.net/xBEjQ/6/

HTML

<div class="block">
    <div class="popup"></div>
    <div class="image"></div>
</div>

<强>jQuery

$(".block .image").mouseover(function(){
    $(this).parent().find(".popup").show();
});

$(".block .popup").mouseout(function() {
    $(this).hide();
});

<强>CSS

.block { position: relative; width: 400px; height: 400px; background: #ccc; }
.popup { display: none;
    position: absolute; left: 0; top: 0; width: 200px; height: 200px; background: #eee; z-index: 40; }
.image { position: relative; width: 100px; height: 100px; background: #aaa; z-index: 30;

Updated your jsfiddle: http://jsfiddle.net/xBEjQ/6/

HTML

<div class="block">
    <div class="popup"></div>
    <div class="image"></div>
</div>

jQuery

$(".block .image").mouseover(function(){
    $(this).parent().find(".popup").show();
});

$(".block .popup").mouseout(function() {
    $(this).hide();
});

CSS

.block { position: relative; width: 400px; height: 400px; background: #ccc; }
.popup { display: none;
    position: absolute; left: 0; top: 0; width: 200px; height: 200px; background: #eee; z-index: 40; }
.image { position: relative; width: 100px; height: 100px; background: #aaa; z-index: 30;
时间海 2024-10-07 12:48:06

鼠标悬停时显示弹出窗口
隐藏弹出窗口鼠标移出时的弹出窗口

http://jsfiddle.net/generalhenry/WkH6q /

show the popup on mouseover
hide the popup on mouseout of the popover

http://jsfiddle.net/generalhenry/WkH6q/

临风闻羌笛 2024-10-07 12:48:06
$(".block .image").mouseover(
    function(){
        $(this).parent().find(".popup").show();
    }
);
$(".block .popup").mouseout(
    function(){
        $(this).hide();
    }
);

这仅适用于“图像”上方有“弹出窗口”的情况。它闪烁的原因是,一旦“弹出窗口”显示,它就会触发“图像”上的“鼠标悬停”,从而隐藏“弹出窗口”,

只要“弹出窗口”不位于顶部,您的代码就可以正常工作的“图像”。

$(".block .image").mouseover(
    function(){
        $(this).parent().find(".popup").show();
    }
);
$(".block .popup").mouseout(
    function(){
        $(this).hide();
    }
);

This only applies if you have the "popup" over top of the "image". The reason it's blinking is because as soon as the "popup" shows it's triggering the "mouseout" on the "image" and thus hiding the "popup"

Your code will work fine as long as the "popup" isn't positioned over top of the "image".

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