繁体   English   中英

chrome setTimeout和淡入淡出

[英]chrome setTimeout and fade

我试图做一个div淡出淡出。 我正在使用JQuery,但是所有延迟方法都不能在Chrome 16中使用,在FF 10中都可以。

msgCenter.style.display = "inline";
setTimeout('$("#messageCenter").hide("fade", { }, 1000);',4000);
$('#messageCenter').delay(4000).fadeOut();

这些都不在Chrome中起作用。

这将在Chrome中运行,但没有褪色效果:

setTimeout('$("#messageCenter").hide();',4000);

谁能告诉我为什么? 还有一种方法可以为Chrome添加褪色效果吗? 谢谢阅读。

另一个解决方案:

setTimeout(function() {
    $("#messageCenter").css('display', 'block').fadeOut();
}, 4000);

而且,如果fadeIn也遇到问题:

$("#messageCenter").css({display: 'block', opacity: 0}).fadeIn();

您必须使用JQuery动画,例如以下之一:

setTimeout('$("#messageCenter").fadeOut();', 4000);
setTimeout('$("#messageCenter").animate({ opacity: 0.0 }, 1000, function() { /* Animation complete */});', 4000);

您的第二个选项应该起作用。 在这里设置了一个可在Chrome 16.0.912.77上运行的jsfiddle。

如果我将其设置为

msgCenter.style.display = "block";

它适用于上述所有选项! 对我来说似乎很奇怪。 有人知道为什么必须将其阻止而不是内联吗?

这个怎么样:

setTimeout(function() {
    $('#messageCenter').css("display","block").fadeOut(4000,function() {
        $(this).css("display","inline");    
    });
});

您还可以try $("#messageCenter").hide(4000) ...这将产生收缩动画...但是对于您而言,请使用$("#messageCenter").fadeIn(4000)$("#messageCenter").fadeOut(4000)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM