javascript - Laggy fade in fade out for a background -


i want background image web page fade out next image fades in, so:

    var backgrounds = [];     backgrounds[0] = './img/bg.jpg';     backgrounds[1] = './img/bg2.jpg';     backgrounds[2] = './img/bg3.jpg';    function changebackground() {     currentbackground++; if(currentbackground > backgrounds.length-1) currentbackground = 0;  $('.bgcontainer').fadeout(1500,function() {     $('.bgcontainer').attr('src', backgrounds[currentbackground]);     $('.bgcontainer').fadein(3000); });        settimeout(changebackground, 5000); } 

and working fine, each time next image fades in other elements start dropping frames , become laggy. there way reduce frame drops?

.bgcontainer{ position:fixed; z-index: -1; width:100vw; height:100%; top:0; }  <img class="bgcontainer" src = "./img/bg.jpg"> 

i don't know if can use css transitions browser compatibility try like:

.bgcontainer {     transition: opacity 1500ms ease-in-out; } 

and

$('.bgcontainer').css('opacity', 0);  settimeout(function() {     $('.bgcontainer').attr('src', backgrounds[currentbackground]);     $('.bgcontainer').css('opacity', 1); }, 1500); 

this way not using javascript change css properties use css3 fade backgrounds opacity.

way less laggy javascript animations work on modern browsers. ie10+


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -