jQuery淡出闪烁

我有jQuery fade在这里http://dougie.thewestharbour.com/

当你将鼠标悬停在.main-overlay div上时,我希望它会淡出然后当你将鼠标从它上面移开时,我希望它能够淡入.

但是,你可以看到它现在只是闪烁.我猜这是因为div消失所以当它消失时它被视为鼠标输出,但我不知道如何去解决它.

这是我的javascript:

$(document).ready(function () {


    $('.main-overlay').hover(

        //MouSEOver,fadeIn the hidden hover class 
        function() {

            $(this).fadeOut('1000');

        },//MouSEOut,fadeOut the hover class
        function() {

            $(this).fadeIn('1000');   

    }).click (function () {

        //Add selected class if user clicked on it
        $(this).addClass('selected');

    });

});

这是叠加div附加到的项目之一:

<li><div class="main-overlay"></div><span class="caption">The store front</span><img src="http://dougie.thewestharbour.com/wp-content/uploads/store-front.jpg" alt="store front" title="store-front" width="730" height="360" class="alignnone size-full wp-image-98" /></li>

谢谢,

解决方法

之所以发生这种情况是因为fadeOut的结尾处有一个显示:none,所以当你在fadeOut完成后移动你的鼠标时,它会触发unhover功能.相反,只需为不透明度设置动画:
$('.main-overlay').hover(function() {
    $(this).animate({opacity: 0},1000);
},function() {
    $(this).animate({opacity: 1},1000);
})

Example →

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...