如何顯示div 2秒,然後在無限循環中隱藏它4秒?我使用jQuery的animate()
函數,因爲我也想使用CSS轉換。jQuery顯示div 2秒,然後在循環中隱藏4秒
function animatedText() {
setTimeout(function() {
$('.text').animate({ opacity: 1 }, 200, function() {
setTimeout(function() {
$('.text').animate({ opacity: 0 }, 200);
}, 1800);
});
}, 3800);
}
setInterval(animatedText(), 6000);
這裏是我的小提琴:https://jsfiddle.net/od6gm8t3/
你'setInterval'不運行任何東西,因爲號召'animatedText'不返回任何東西。如果應該每6秒調用一次'animatedText',那麼你需要編寫'setInterval(animatedText,6000)'。而不是使用間隔和超時,你應該使用jQuery的'延遲'功能和動畫的結束回調。 –
我明白了。謝謝! – Plastik