Jquery悬停显示div并停留

标签 jquery image hover fade out

我正在构建一个小型 jquery 脚本,当您将鼠标悬停在图像上时,该脚本会显示一个 div(以显示产品的技术规范)。我的问题是,当您悬停时,新的 div 会加载,然后它就会消失,因为鼠标不再悬停在图像上,而是悬停在新的 div 上。知道如何解决这个问题,使其不闪烁吗?

http://jsfiddle.net/uWRLr/

$(document).ready(function(){
    $('.hover').hover(function(){
        $('.techinfo').fadeIn(500)
    },function(){
        $('.techinfo').fadeOut(500)
    })
})

最佳答案

我会将所有内容包装在容器中,并将悬停事件附加到容器,例如:

<div class="main-container">
    <img class="hover" src="http://charlescorrea.com.br/blog/wp-content/uploads/2012/02/google-small.png" />
    <div class="techinfo">Here's the text</div>
</div>

...以及你的 Javascript:

$(document).ready(function(){
    $('.main-container').hover(function(){
        $('.techinfo').fadeIn(500)
    },function(){
        $('.techinfo').fadeOut(500)
    })
});

这样,当您进入/退出容器时,该功能就可用。 Here's a fiddle .

关于Jquery悬停显示div并停留,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18992960/

相关文章:

jquery 像电影字幕一样移动文本

jquery - Firefox 仅在使用 jQuery 时出现错误 - handleObj.handler.apply 不是函数

javascript - jquery ajax 数据对象 : functions are called

html - 照片和缩略图有什么区别?

html - 将鼠标悬停在文字上后让文字消失

html - 为什么当我在 DP 框中移动鼠标光标时背景在悬停时闪烁

javascript - 按项目修改 X-Editable 中的按钮模板?

打不开C图

javascript - 在 Jquery 中渲染图像抛出 500(内部服务器错误)

html - IE 怪癖模式 a :hover style issue