2013-01-16 36 views
0

嘗試了幾個選項後,我無法使文本淡入淡出。 無論我嘗試,整個動畫只是凍結,加入這樣的事情以下演示中的FadeIn和fadeOut

$("#headertxt".fadeIn('slow').css({"display" : "block"}); 

$("#headerimg" + currentContainer).fadeOut(function() { 
setTimeout(function() { 
$("#headertxt".fadeIn({"display" : "block"}); 
animating = false; 
}, 500); 
}); 

$("#headerimg" + currentContainer).fadeOut(function() { 
setTimeout(function() { 
$("#headertxt".fadeOut({"display" : "block"}); 
animating = false; 
}, 5000); 
}); 

原來這是demo

而且here's jfiddle

+1

您應該減少代碼在你的問題的準系統例如工作。 http://sscce.org/ – j08691

+0

你能把你的小提琴切成只是你問的部分嗎? –

回答

0

變化

$("#headertxt".fadeIn('slow').css({"display" : "block"}); //this will not work 

$("#headertxt").fadeIn('slow', function(){ 
    $(this).css('display', 'block'); 
}); 
// apply css after animation. 
+0

無論如何,jQuery在'fadeIn'結束時將'display'設置爲'block'。 – Blazemonger

+0

@Blazemonger正確,我在回調中添加了css部分,通常你應該在動畫之後應用css。 而且'#headertxt'可以是內聯元素,也可以將其轉換爲塊元素。 – HamidRaza

+0

@HamidRaza感謝這是淡入淡出,但現在我無法設置fadeOut – Helena

0

淡入和淡出,即使不要拿物體作爲參數,所以我不確定你爲什麼擁有這些物體。您還在.fadeIn之前缺少括號。

嘗試這樣:

$("#headerimg" + currentContainer).fadeOut(function() { 
    setTimeout(function() { 
     $("#headertxt").fadeIn(); 
     animating = false; 
    }, 500); 
});