A couple of days before I searched for a similar explanation. Answer number two was pretty good, but as I see it, it needs a fading effect. I accomplished this (and much more). Here is the code:
var bgArr = ['img1.png', 'img2.png', 'img3.png', 'img4.png']; var bgText = ['text1', 'text2', 'text3', 'text4']; var i=0; var left = 0; $(document).ready(function() { timer = setTimeout("changeBG()", 7000); $("#slider_left").on("click", function(){ i = i-2; if(i<-1) i = bgArr.length-2; left = 1; clearTimeout(timer); changeBG(); }); $("#slider_right").on("click", function(){ if(i>(bgArr.length-1)) i = 0; clearTimeout(timer); changeBG(); }); }); function changeBG() { i++; if(i>(bgArr.length-1)) i = 0; $('#slider_up').stop().fadeIn(1000, function(){ if(left == 1){ var a = i+1; if(i == bgArr.length-1) a = 0; }else{ var a = i-1; if(i == 0) a = bgArr.length-1; } left = 0; $("#slider_up").css("background", "url("+bgArr[a]+") no-repeat center center white"); $("#slider_up").css('opacity',0).show().animate({opacity:1}); $("#slider_down").css("background", "url("+bgArr[i]+") no-repeat center center white"); $("#slider_up").css('opacity',1).show().animate({opacity:0}); $(".text_holder").fadeOut(1000, function() { $(this).html(bgText[i]); $(this).fadeIn(500); }); }); timer = setTimeout("changeBG()", 7000); };
I explained this on my blog: http://blog.braovic.com/css-background-slider-and-slideshow/
Hope this helps all of you. Best, Ante.
source share