簡體   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