javascript - different pages loading into div with delay -


i'm trying load 3 different html files div, 1 after other, delay of 5 seconds. after cycles through 3 want carry on repeating. tried using timeout still not working.any appreciated.. code snippet below

<script type="text/javascript">     $(document).ready(function() {          jquery(window).load (function timeout() {             settimeout(function () {                 if($("#news_sections").hasclass("news1")){                     $("#news_sections").attr('class', "news2");                     $( "#news_sections" ).load( "section2.html" );                 }else if($("#news_sections").hasclass("news2")){                     $("#news_sections").attr('class', 'news3');                     $( "#news_sections" ).load( "section3.html" );                 }else{                     $("#news_sections").attr('class', 'news1');                     $( "#news_sections" ).load( "section1.html" );                 };                  timeout();              }, 4000);         });     });     }); </script> 

you can use this, instead of changing classes , depending on them.

in case have more 10 sectionx.html files, need write lot of code there. if make counter, have change if statement (count > x) x = number of templates have.

var count = 1;  setinterval(function () {   // if count more 3, reset count 1.   if (count > 3) {     count = 1;   }    // if using "newsx" class looping propose only,   // can remove .attr() method in solution.    $("#news_sections").attr('class', "news" + count);    // clear news section   $("#news_sections").empty();    // load count number sectionx.html file   // increase count number 1 (count++)   $("#news_sections").load( "section" + count++ + ".html" );  }, 1500); 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -