gpt4 book ai didi

jquery - 使用 jquery 在悬停时切换放置在另一个 div 中的 div

转载 作者:太空宇宙 更新时间:2023-11-04 11:47:16 25 4
gpt4 key购买 nike

希望在客户将鼠标悬停在产品上时创建一个快速查看选项卡。

我几乎已经解决了它,但我的问题是,一旦您的鼠标移到快速查看 div 按钮上,该按钮就开始消失,因为它在技术上离开了触发 div。我如何保持它??

这里是我使用的 jquery

    $("#cat_product").hover(
function () {
$(".quickview").fadeIn();
},
function () {
$(".quickview").fadeOut();
}
);

这是我用来测试的 fiddle - https://jsfiddle.net/a0j96wyc/

最佳答案

我建议也为 .quickview 添加悬停事件。当您将鼠标悬停在 #cat_product 上并悬停在 .quickview 上时,.quickview 的悬停事件将接管并防止按钮淡出。

由于该按钮完全包含在 #cat_product 中,因此我没有为 .quickview 添加“悬停关闭”事件。如果不将鼠标悬停在 #cat_product 上,您永远不会将鼠标悬停在按钮上。

此外,我正在使用 stop()清除动画队列并防止淡入淡出闪烁。

$("#cat_product").hover(
function () {$(".quickview").stop(true,true).fadeIn();},
function () {$(".quickview").fadeOut();}
);

$(".quickview").hover(
function () {$(this).stop(true, true).show(0);}
);
.quickview {
display: block;
}
.hidden {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<a href="http://www.mayfieldfurniture.co.uk/Bedroom+Furniture/Chest+of+Drawers/1567493/ViewProduct/" class="normal_text" style="text-decoration:none">

<div id="cat_product" style="width:250px; border:1px solid #000">

<div class="options_overlay_cat">
<div style='text-align:center'>
<div style="height:170px">

<img class="lazy" src="//cdn.mayfieldfurniture.co.uk/images/?src=img-1567493.jpg&amp;w=170" data-original="//cdn.mayfieldfurniture.co.uk/images/?src=img-1567493.jpg&amp;w=170" title="Mark Webster MWG017 Geo 6 Drawer Tallboy" border="0" style="display: inline;">
<noscript>&lt;img src="//cdn.mayfieldfurniture.co.uk/images/?src=img-1567493.jpg&amp;w=170"&gt;</noscript>
</div>
<div style="text-align:left; padding:20px 8px 20px 8px"><b><font style="font-size:14px; color:#00CC00">Geo</font></b>
<br><font style="font-size:13px">6 Drawer Tallboy</font>
<br>

<div style="padding-top:8px;">
<div style="float:left"><font class="small_black_text">Was <strike>£579</strike></font>
<br><font style=" color:#C50132" class="product_price_18">£489</font>
</div>
<div style="padding:5px; background-color:#C50132; margin-top:5px; color:white; float:right"><b>SAVE £90<b></b></b>
</div>
<div style="clear:both"></div>
</div>

<div style="height:20px;padding-top:10px;">
<div>
<div style="float:left; width:14px; height:14px; border:1px solid #999999; margin-left:3px;">
<img src="//cdn.mayfieldfurniture.co.uk/images/finishes/?src=geo_lacquered.jpg&amp;w=14" title="Lacquered" border="0">
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div id='quick' class='quickview hidden' style="position:absolute; margin: -270px 0px 0px 80px; height:48px; width:108px">
<a href="//www.mayfieldfurniture.co.uk/modules/quickview/index.php?id='.$row[0].'" class="fancybox fancybox.iframe">
<img src="//cdn.mayfieldfurniture.co.uk/images/quickview_button.png" height="48" />
</a>
</div>
</a>

编辑:

CSS 解决方案

稍作调整您的 HTML 结构,您就可以使用 CSS transitions为不透明度设置动画并避免完全使用 JavaScript。示例如下:

.quickview {
opacity: 0;
-webkit-transition: opacity .2s ease-in-out 0s;
transition: opacity .2s ease-in-out 0s;
}
div#cat_product:hover div.quickview {
opacity: 1;
}
<a href="http://www.mayfieldfurniture.co.uk/Bedroom+Furniture/Chest+of+Drawers/1567493/ViewProduct/" class="normal_text" style="text-decoration:none">

<div id="cat_product" style="width:250px; border:1px solid #000">

<div class="options_overlay_cat">
<div style='text-align:center'>
<div style="height:170px">

<img class="lazy" src="//cdn.mayfieldfurniture.co.uk/images/?src=img-1567493.jpg&amp;w=170" data-original="//cdn.mayfieldfurniture.co.uk/images/?src=img-1567493.jpg&amp;w=170" title="Mark Webster MWG017 Geo 6 Drawer Tallboy" border="0" style="display: inline;">
<noscript>&lt;img src="//cdn.mayfieldfurniture.co.uk/images/?src=img-1567493.jpg&amp;w=170"&gt;</noscript>
</div>
<div style="text-align:left; padding:20px 8px 20px 8px"><b><font style="font-size:14px; color:#00CC00">Geo</font></b>
<br><font style="font-size:13px">6 Drawer Tallboy</font>
<br>

<div style="padding-top:8px;">
<div style="float:left"><font class="small_black_text">Was <strike>£579</strike></font>
<br><font style=" color:#C50132" class="product_price_18">£489</font>
</div>
<div style="padding:5px; background-color:#C50132; margin-top:5px; color:white; float:right"><b>SAVE £90<b></b></b>
</div>
<div style="clear:both"></div>
</div>

<div style="height:20px;padding-top:10px;">
<div>
<div style="float:left; width:14px; height:14px; border:1px solid #999999; margin-left:3px;">
<img src="//cdn.mayfieldfurniture.co.uk/images/finishes/?src=geo_lacquered.jpg&amp;w=14" title="Lacquered" border="0">
</div>
</div>
</div>
</div>
</div>
</div>

<div id='quick' class='quickview hidden' style="position:absolute; margin: -270px 0px 0px 80px; height:48px; width:108px">
<a href="//www.mayfieldfurniture.co.uk/modules/quickview/index.php?id='.$row[0].'" class="fancybox fancybox.iframe">
<img src="//cdn.mayfieldfurniture.co.uk/images/quickview_button.png" height="48" />
</a>
</div>

</div>
</a>

关于jquery - 使用 jquery 在悬停时切换放置在另一个 div 中的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30896770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com