Reputation: 4008
I have a simple background image cross fader: http://jsfiddle.net/jRDkm/2/ The basis for this code was taken from here: http://snook.ca/archives/javascript/simplest-jquery-slideshow
For some reason though it does only one repetition then fades to white. How can I tweak my code so that it constantly repeats itself?
JS:
function slideshow() {
$('#fullscreen-slider li:gt(0)').hide();
setInterval(function(){
$('#fullscreen-slider :first-child').fadeOut()
.next('li').fadeIn()
.end().appendTo('#fullscreen-slider');
}, 3000);
};
Upvotes: 2
Views: 201
Reputation: 9370
Try this : http://jsfiddle.net/jRDkm/4/
function slideshow() {
$('#fullscreen-slider li:gt(0)').hide();
setInterval(function(){
$('#fullscreen-slider li:eq(0)').fadeOut()
.next('li').fadeIn()
.end().appendTo('#fullscreen-slider');
}, 3000);
};
Upvotes: 0
Reputation: 206508
/* located within plugins.js */
function fitElements() {
$('ul#fullscreen-slider li').height( $(window).height() ).width( $(window).width() );
}
function slideshow() {
var n = 0;
var $LI = $('#fullscreen-slider li');
$LI.hide().eq(n).show();
setInterval(function(){
$LI.eq(n++%$LI.length).fadeTo(600,1).siblings().fadeTo(600,0);
}, 3000);
}
$(document).ready(function() {
fitElements();
slideshow();
});
Upvotes: 0
Reputation: 5910
Your selector is wrong. Try
$('#fullscreen-slider li:first').fadeOut()
.next('li').fadeIn()
.end().appendTo('#fullscreen-slider');
DEMO: http://jsfiddle.net/jRDkm/5/
Upvotes: 2