简体   繁体   English

chrome setTimeout和淡入淡出

[英]chrome setTimeout and fade

I am trying to do a delayed fade out of a div. 我试图做一个div淡出淡出。 I am using JQuery but none of the delay methods work in Chrome 16, all is fine in FF 10. 我正在使用JQuery,但是所有延迟方法都不能在Chrome 16中使用,在FF 10中都可以。

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

Neither of these work in Chrome. 这些都不在Chrome中起作用。

This will work in Chrome but has no fade effect: 这将在Chrome中运行,但没有褪色效果:

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

Can anyone tell me why? 谁能告诉我为什么? Also is there a way I can add a fading effect to Chrome? 还有一种方法可以为Chrome添加褪色效果吗? Thanks for reading. 谢谢阅读。

Yet another solution: 另一个解决方案:

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

And if fadeIn is encountering issues, too: 而且,如果fadeIn也遇到问题:

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

You have to use a JQuery animation, like one of the following: 您必须使用JQuery动画,例如以下之一:

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

Your second option should work. 您的第二个选项应该起作用。 I set up a jsfiddle here which works on Chrome 16.0.912.77. 在这里设置了一个可在Chrome 16.0.912.77上运行的jsfiddle。

If I set it to 如果我将其设置为

msgCenter.style.display = "block";

it works for all the options mentioned above! 它适用于上述所有选项! Seems strange to me. 对我来说似乎很奇怪。 Anyone know why it must be block and not inline? 有人知道为什么必须将其阻止而不是内联吗?

How about this: 这个怎么样:

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