我有一个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();
});
Run Code Online (Sandbox Code Playgroud)
如您所见,我也在使用jQuery来帮助我.问题是在它运行一次并tmnlSpinner再次运行之后(除了因为它已经运行一次,currentVis不再为null).当它运行fadeOut时$currentVis,它就会停止工作.Google Chrome并未就任何类型的错误向我提供任何反馈.有人看到任何问题吗?