javascript - Fade in new background and fade out after 10s -


i've tried make website change background every 10 seconds. successful. now, want fade them in , fade them out, appear smoothly. i've searched other forumpages , found related questions, wasn't able understand answers well.

javascript:

function run(interval, frames) { var int = 1;  function func() {     document.body.id = "b"+int;     int++;     if(int === frames) { int = 1; } }  var swap = window.setinterval(func, interval); }  run(10000, 6); //milliseconds, frames 

css:

#b1 { background-image: url("standaard01.jpg"); } #b2 { background-image: url("standaard02.jpg"); } #b3 { background-image: url("standaard03.jpg"); } #b4 { background-image: url("standaard04.jpg"); } #b5 { background-image: url("standaard05.jpg"); } #b6 { background-image: url("standaard06.jpg"); } #b7 { background-image: url("standaard07.jpg"); } #b8 { background-image: url("standaard08.jpg"); } #b9 { background-image: url("standaard09.jpg"); } #b10 {  background-image: url("standaard10.jpg"); } 

unfortunately it's not possible transition between 2 images set background of single element. (correction: is, animating background-image property of element - given browser support)

however, can fade 1 element out while element lays behind it.

jquery has method called .fadetoggle() use in case.

set "stack" of img elements or divs bg images, positioned on top of eachother, position:absolute, left, , top css properties.

then, in javascript loop, every 10 seconds, .fadetoggle() visible div, revealing next image. keep track of state index variable.

upon reaching final element, fade top image again. before second element fades, .show() remaining elements once again visible revealing.

a note z-index: css property z-index position elements either in front, or behind other elements. wise set correct z-index of each item either in it's css class, or programmatically on loading page.

image size note: if images or divs different dimensions, fade 1 in, while fading other out. here can talk different crossfading methods that's beyond scope of discussion

good luck :)


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -