Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to stop setInterval() on slidetoggle() then restart again?
    primarykey
    data
    text
    <p>I have looked at all the other answers similiar to this question but i can't make them fit my scenario.</p> <p>i have a page that has a sidebar that contains 15 results that auto refreshes, which is fine. There is a link that loads up an external page into a div with an overlay. then this new <code>div</code> with the FULL list of the results also auto refreshes whilst its open. (don't want both divs auto-refreshing in background uneccesarily)</p> <p>in this <code>full list</code> div each result has a <code>jquery slideToggle()</code> function to display more information.</p> <p>what i am TRYING(and failing) to do is make the auto refresh stop whilst this <code>slideToggle</code> is displaying information, cos otherwise when the page refreshes it goes back to <code>display:none</code>.</p> <p>here is my latest attempt: </p> <p><strong>html</strong></p> <pre class="lang-html prettyprint-override"><code>main page has div to load into... &lt;div id="full_list"&gt; loading... &lt;/div&gt; </code></pre> <p><strong>external page with the full list</strong></p> <pre class="lang-html prettyprint-override"><code>&lt;div class="events_list"&gt; &lt;!--container for events --&gt; &lt;ul&gt;&lt;li&gt; &lt;div class="full_event"&gt; &lt;!--each event in a list--&gt; #1&lt;b&gt; 500 m race &lt;/b&gt; &lt;!--this bit always seen --&gt; &lt;div class="event_slide"&gt; &lt;!--this div is slideToggled() --&gt; &lt;b&gt;500m race &lt;/b&gt;&lt;br&gt; &lt;div class="evntdescription"&gt; run 500mrun 500mrun 500mrun 500mrun 500mrun 500m &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/li&gt;&lt;/ul&gt; &lt;/div&gt; </code></pre> <p><strong>now my attempted javascript</strong></p> <pre class="lang-js prettyprint-override"><code>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 up the div // overlay.fadeIn(1000).appendTo(document.body); $('#full_list').load('eventlist.php'); //loads external page// $('#full_list').fadeIn(800, function() { autoRefresh (); //start the auto refresh/ $("body").on("click",".full_event", function(e){ $(this).children('div.event_slide').slideToggle(300, function() { autoRefresh (); //thought it might work if i add the function //here as well // }); }); }); $("body").on("click","#close", function(e){ //closes div// overlay.fadeOut(300); $("#full_list").fadeOut(300); }); return false; }); </code></pre> <p>basically it doesnt do anything. i have made it work if i get rid of the second <code>autoRefresh</code> function, but it won't stop the function from going. just keeps on refreshing, also not sure how to stop the refresh when i close the div aswell. let me know if you need more info.</p> <p>thanx!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload