У меня есть следующий код:
$(document).ready(function() {
var bgCounter = 0,
backgrounds = [
"images/2.png",
"images/1.png",
"images/3.png"
];
function changeBackground()
{
bgCounter = (bgCounter+1) % backgrounds.length;
$('#page').css('background', '#000 url('+backgrounds[bgCounter]+') no-repeat');
setTimeout(changeBackground,100000);
}
changeBackground();
});
Мне нужно добавить эффект fade in/out, между изменениями фона. Любые указания?
Просто добавьте это:
$('#page').fadeIn()
до
$('#page').css('background', '#000 url('+backgrounds[bgCounter]+') no-repeat');
И это:
$('#page').fadeOut()
после этого..
Попробуй это:
$(document).ready(function() {
var bgCounter = 0,
backgrounds = [
"images/2.png",
"images/1.png",
"images/3.png"
];
function changeBackground()
{
bgCounter = (bgCounter+1) % backgrounds.length;
$('#page').animate({
opacity: 0
}, 0).css({
'background-image': 'url('+backgrounds[bgCounter]+')'
}).animate({opacity: 1}, 1000);
setTimeout(changeBackground,10000);
}
changeBackground();
});