1
我有一個JavaScript腳本,希望每隔幾秒就會有多個div淡入/淡出。一次只能看到一個。我創建了以下任務:腳本剛停止
var tmnlSpDelay = 5000;
var $currentVis = null;
tmnlFadeIn = function ($re) {
$re.css("display", "inline");
$re.fadeIn('slow', "");
$currentVis = $re;
setTimeout("tmnlSpinner();", tmnlSpDelay);
}
tmnlSpinner = function() {
var $random_elem = $('.topcontent').eq(Math.floor(Math.random() * $('.topcontent').length));
if ($currentVis != null) {
$currentVis.fadeOut('slow', "function() { tmnlFadeIn($random_elem) }");
} else {
tmnlFadeIn($random_elem);
}
}
$(document).ready(function() {
tmnlSpinner();
});
正如您所看到的,我也在使用jQuery來幫助我。問題出現在運行一次後再次運行tmnlSpinner
(除了因爲它已經運行一次,currentVis
不再爲空)。當它在$currentVis
上運行fadeOut時,它會停止工作。谷歌瀏覽器沒有給我任何關於任何錯誤的反饋。有人看到任何問題嗎?