javascript - 悬停弹出窗口如此快速地闪烁

标签 javascript jquery

我在悬停时创建了一个弹出窗口,但它闪烁得非常快。我也尝试应用超时、延迟功能,但没有成功。也许我做错了。

$(document).on('mouseout', '.lash-opt', function(){
    $('#hover-popup').css({display: 'none'});
});

$(document).on('mouseover', ' .lash-opt', function() {
    $('#hover-popup').css({display: 'block'});
});
.lash-opt img{
    width:100px;
    height:100px;
    border:2px solid black;
}
#hover-popup{
    display:none;
}
#hover-popup img{
    width:100px;
    height:100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

<div class="lash-opt-container"><input id="lash-base-url" type="hidden" value="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSayqdJ-F4wF8rxhaC1XMBglgXLVeR30A3NyOLG7bDSNTlcyOSI" />
 
 
<span id="style-no-pictures-please" class="lash-opt">
    <img src="http://www.ikea.com/PIAimages/0417314_PE579390_S5.JPG" />
     <label>3</label>
    </span>
</div>

<div id="hover-popup">
    <img id="hover-popup-img" src="http://www.ikea.com/gb/en/images/products/kalas-mug-assorted-colours__0145357_pe304804_s5.jpg" />
    <p>The Perfect basic for the non-basic. Our most popular style, these versatile lashes follow and amplify the natural length of your lashes for an everyday natural look.</p>
</div>

最佳答案

使用 fadeIn()fadeOut() 而不是 display: nonedisplay: block 你可以使用delay()设置fadeOut前的延迟时间。

$(document).on('mouseout', '.lash-opt', function() {
  $('#hover-popup').delay(1000).fadeOut(500);
//Set delay time -----------^

//Set transition time--------------------^
});

$(document).on('mouseout', '.lash-opt', function() {
  $('#hover-popup').delay(1000).fadeOut(500);
});
$(document).on('mouseover', ' .lash-opt', function() {
  $('#hover-popup').fadeIn(500);
});
.lash-opt img {
  width: 100px;
  height: 100px;
  border: 2px solid black;
}

#hover-popup {
  display: none;
}

#hover-popup img {
  width: 100px;
  height: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

<div class="lash-opt-container"><input id="lash-base-url" type="hidden" value="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSayqdJ-F4wF8rxhaC1XMBglgXLVeR30A3NyOLG7bDSNTlcyOSI" />




  <span id="style-no-pictures-please" class="lash-opt"><img src="http://www.ikea.com/PIAimages/0417314_PE579390_S5.JPG" /> <label>3</label></div>

    </span>



  <div id="hover-popup"><img id="hover-popup-img" src="http://www.ikea.com/gb/en/images/products/kalas-mug-assorted-colours__0145357_pe304804_s5.jpg" />
    <p>The Perfect basic for the non-basic. Our most popular style, these versatile lashes follow and amplify the natural length of your lashes for an everyday natural look.</p>
  </div>
</div>

关于javascript - 悬停弹出窗口如此快速地闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48163396/

相关文章:

javascript - 如何在 Javascript 中更新嵌套 JSON 键?

javascript - 我应该如何测试一个对象是否是 XML 文档(以跨浏览器的方式)

javascript - 遇到循环不够迭代的问题

javascript - knockout 具有相同名称变量冲突的多个 View 模型?

javascript - 在类中设置 mouseup 事件

javascript - if 语句不返回 true

javascript - jQuery/JS setTimeout/clearTimeout

php - 使用Jquery实现翻转效果

javascript - Jquery div 淡入淡出

JQuery 在表中查找表并选择单选按钮