javascript - How to use setInterval -


on website want have 2 background images changing setinterval don't know how let work/

css:

body {         padding-top: 20px;         padding-bottom: 40px;         background-image: url(/assets/img/image1.jpg), url(/assets/img/image2.jpg);         background-repeat: repeat-x, repeat;         -webkit-background-size: cover;         -moz-background-size: cover;         -o-background-size: cover;         background-size: cover;     } 

.js:

$(document).ready(function () {      (function () {         var curimgid = 0;         var numberofimages = 2; // change number of background images         window.setinterval(function () {             $('body').css('background-image', 'url(/background' + curimgid + '.jpg)');             curimgid = (curimgid + 1) % numberofimages;         }, 15 * 1000);     })(); }); 

i need switch between image1.jpg , image2.jpg using setinterval

edit

i have change js to:

  $(document).ready(function () {         setinterval(function () {             $('body').toggleclass("/assets/style/background/images1.css", "/assets/style/background/images2.css");         }, 15000);     }); 

added 2 css classes:

images1.css:

body {      background-image: url(/assets/img/image1.jpg); } 

images2.css:

body {      background-image: url(/assets/img/image2.jpg); } 

but still background not changing

to simplify things, i'll have 2 css classes images want. set first class default , this:

$(document).ready(function () {     setinterval(function() {           $('body').toggleclass('class2');     }, 15000);  }); 

working demo


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -