我在这个网站上使用了两张背景图片,我想让它们每5秒自动更换。请有经验的人查看我的jQuery代码并告诉我哪里出了问题?
$(function() {
var body = $(‘body’);
var backgrounds = new Array(
‘url(images/hso-palmtree-background.jpg)’,
‘url(images/hso-boardwalk-background.jpg)’
);
var current = 0;
function nextBackground() {
body.css(
‘background’,
backgrounds[current = ++current % backgrounds.length]
);
setTimeout(nextBackground, 5000);
}
setTimeout(nextBackground, 5000);
body.css(‘background’, backgrounds[0]);
});