javascript - how to stop setInterval() on slidetoggle() then restart again? -
i have looked @ other answers similiar question can't make them fit scenario.
i have page has sidebar contains 15 results auto refreshes, fine. there link loads external page div overlay. new div
full list of results auto refreshes whilst open. (don't want both divs auto-refreshing in background uneccesarily)
in full list
div each result has jquery slidetoggle()
function display more information.
what trying(and failing) make auto refresh stop whilst slidetoggle
displaying information, cos otherwise when page refreshes goes display:none
.
here latest attempt:
html
main page has div load into... <div id="full_list"> loading... </div>
external page full list
<div class="events_list"> <!--container events --> <ul><li> <div class="full_event"> <!--each event in list--> #1<b> 500 m race </b> <!--this bit seen --> <div class="event_slide"> <!--this div slidetoggled() --> <b>500m race </b><br> <div class="evntdescription"> run 500mrun 500mrun 500mrun 500mrun 500mrun 500m </div> </div> </div> </li></ul> </div>
now attempted javascript
var refreshdata; var infodisplay = $('.event_slide').css('display'); function autorefresh () { if(infodisplay == 'none') { refreshdata = setinterval(function() { $('#full_list').load('eventlist.php'); }, 1000); } else { clearinterval(refreshdata); } }; $("#view_events").click(function(){ //this opens div // overlay.fadein(1000).appendto(document.body); $('#full_list').load('eventlist.php'); //loads external page// $('#full_list').fadein(800, function() { autorefresh (); //start auto refresh/ $("body").on("click",".full_event", function(e){ $(this).children('div.event_slide').slidetoggle(300, function() { autorefresh (); //thought might work if add function //here // }); }); }); $("body").on("click","#close", function(e){ //closes div// overlay.fadeout(300); $("#full_list").fadeout(300); }); return false; });
basically doesnt anything. have made work if rid of second autorefresh
function, won't stop function going. keeps on refreshing, not sure how stop refresh when close div aswell. let me know if need more info.
thanx!
try clearing interval when asynchronous loading has completed:
function autorefresh () { refreshdata = setinterval(function() { $('#full_list').load('eventlist.php', function() { clearinterval(refreshdata); }); }, 1000); };
Comments
Post a Comment