var colors = Array('#2a83bd', '#982426', '#088C51', '#CADB1B');
var color_index = 0;
var interval = 1000; // transition speed
function tbc_fadebg() {
$('#topbanner_container').animate({ backgroundColor: colors[color_index] }, interval, 'linear', function() {
if(color_index == colors.length) { color_index = 0; } //If we are at the end of the colors array go back to the beginning.
else { color_index++; } //Lets move to the next color in the colors array.
tbc_fadebg();
});
}
$(document).ready(function() {
if( $(window).width() > 1024 ) {
tbc_fadebg();
}
});
以上是我的代码。如何在此背景循环中将每种背景颜色暂停5秒钟,以及如何将代码放置在哪里?我尝试设置超时,但是显然我做错了,无法弄清楚将其放置在此代码中的位置。
尝试使用setInterval()
,删除该recursive
通话,
var colors = Array('#2a83bd', '#982426', '#088C51', '#CADB1B');
var color_index = 0;
var interval = 1000; // transition speed
function tbc_fadebg() {
$('#topbanner_container').animate({ backgroundColor: colors[color_index] }, interval, 'linear', function() {
if(color_index == colors.length) { color_index = 0; } //If we are at the end of the colors array go back to the beginning.
else { color_index++; } //Lets move to the next color in the colors array.
});
}
$(document).ready(function() {
if( $(window).width() > 1024 ) {
setInterval(tbc_fadebg,5000);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句