javascript - Is it possible to start/pause auto refreshing content? -


i using script auto refresh content every 10 seconds.

var auto_refresh = setinterval( function () { $('#stats').load('stats.php').fadein("slow"); }, 10000); 

however, need add start/pause button start , pause refresh. how can ?

in general sense can pause effect setinterval() adding flag:

var paused = false,     auto_refresh = setinterval(function (){        if (paused) return false;        $('#stats').load('stats.php').fadein("slow");     }, 10000);  $("#idofpausebutton").click(function() {     paused = !paused;     this.value = paused ? "restart" : "pause"; }); 

i find method simpler using clearinterval() pause , setinterval() again restart.

obviously assumes use single button pause/restart:

<input id="idofpausebutton" value="pause" type="button"> 

demo: http://jsfiddle.net/nnnnnn/nwa56/


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -