javascript - jquery slideshow using background images -
i have div has static background image.
i need create slideshow of background images div.
i able achieve setting timeout , changing background image in css not elegant.
i ideally fade background images out , in, div contains other page elements can not alter opacity in way.
does know of way using jquery??
here's code fades out/in fades out contents of div too.
$("#slideshow").fadeout(5000, function(){ $("#slideshow").css('background-image','url(myimage.jpg)'); $("#slideshow").fadein(5000); });
html:
<div class="slideshow"></div>
css:
.slideshow { position: relative; width: 350px; height: 150px; } .slideshow img { position: absolute; width: 350px; height: 150px; z-index:-1; }
jquery
var images=new array('http://placehold.it/250x150','http://placehold.it/250x150/123456','http://placehold.it/250x150/dbca98'); var nextimage=0; doslideshow(); function doslideshow() { if($('.slideshowimage').length!=0) { $('.slideshowimage').fadeout(500,function(){slideshowfadein();$(this).remove()}); } else { slideshowfadein(); } } function slideshowfadein() { $('.slideshow').prepend($('<img class="slideshowimage" src="'+images[nextimage++]+'" style="display:none">').fadein(500,function(){settimeout(doslideshow,1000);})); if(nextimage>=images.length) nextimage=0; }
Comments
Post a Comment