javascript - Set interval Slider with Random starting <div>, How to traverse through all <divs>? -


i have jsonp request returning block of html this

<div id="slider_wrapper" style="">     <div style="xxx" ><section style="xx">xx</section></div>     <div style="xxx" ><section style="xx">xx</section></div>     <div style="xxx" ><section style="xx">xx</section></div>     <div style="xxx" ><section style="xx">xx</section></div>     ...     ...  </div> 

here number of inner depends on db rows.

after this, sliding content using set interval fallowing

note: here want start sliding random position , not 0th position here id = random number

setinterval(function() {                        $('#slider_wrapper > div:eq('+id+')')                     .fadeout(1000)                     .next()                     .fadein(1000)                     .end()                     .appendto('#slider_wrapper');             },  5000);  

above solution working fine , problem repeats same contents , not start position 0 once reaches last div ,

for example : total number of divs: 5
if random number 2 starts 2,3,4,2,3,4,....not 2,3,4,0,1,

how slide first once reaches end regardless of starting div?

this should :

setinterval(function() {       if(! $("#slider_wrapper:has(div:eq('+id+'))") )         {            id = 0 ;         }                       $('#slider_wrapper > div:eq('+id+')')                     .fadeout(1000)                     .next()                     .fadein(1000)                     .end()                     .appendto('#slider_wrapper');             },  5000); 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -