javascript - How to call a image class on a regular interval -
i having 4 classes inside each class image called
<div id="ban01" class="banner ban01"> </div> <div id="ban02" class="banner ban02"> </div> <div id="ban03" class="banner ban03"> </div> <div id="ban04" class="banner ban04"> </div>
and css class contains
.ban01 { background-image:url(../images/banner/01.jpg); } .ban02 { background-image:url(../images/banner/02.jpg); } .ban03 { background-image:url(../images/banner/03.jpg); } .ban04 { background-image:url(../images/banner/04.jpg); }
and jquery
$(document).ready(function () { var totdivs = $(".banner ban03").length; var currdiv = 0; var myinterval = setinterval(function () { if (currdiv > totdivs) { clearinterval(myinterval); return } $(".banner ban03").eq(currdiv).find('class').trigger("click"); currdiv++; }, 2000); });
how call these classes in regular intervals sorry if repeated question again
html
<div id="ban01" class="banner ban01"> </div> <div id="ban02" class="banner ban02"> </div> <div id="ban03" class="banner ban03"> </div> <div id="ban04" class="banner ban04"> </div>
style
.banner { height: 50px } .ban01 { background: green } .ban02 { background: blue } .ban03 { background: red } .ban04 { background: orange }
javascript
$(document).ready(function () { var totdivs = $(".banner").length; var currdiv = 0; var myinterval = setinterval(change, 2000); function change(){ $(".banner").hide().eq(currdiv).show(); currdiv = (currdiv + 1) % totdivs; } change(); });
Comments
Post a Comment