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">
Comments
Post a Comment