I am trying to create server side image rotate using jquery+php, when the new image is return by back end I want to preload it and when it is done switch background. Everything works for except preload, during the switch there is couple seconds when the screen is just white.
Here is javascript I have
var current='';
function loadNext(){
$.ajax({
url: 'rotate.php?next='+current,
context: document.body
}).done(function($resp) {
current = $resp;
var imageUrl = 'image.php?next='+current;
var img = $('<img />');
img.attr('src', imageUrl);
img.hide();
img.load(function(){
$('body').css('background-image', 'url(' + imageUrl + ')');
$(this).remove();
});
$('body').append(img);
});
}
setInterval(loadNext, 15000);