clearinterval

How can I call clearInterval outside of a function in jQuery? Outside the setInterval

大城市里の小女人 提交于 2019-12-08 07:55:29
问题 function iPadMovie(id) { $(function () { var i = 1; var interval = setInterval(function () { jQuery('.animationMax img').attr({ src: 'http://jdsports.scene7.com/is/image/JDSports/127932jd' + ('0' + i).slice(-2) + '?hei=255&wid=427&resmode=sharp&op_usm=1.1,0.5,0,0&defaultImage=JDSports/sizeImageMissing' }); i++; if (i === 28) i = 1; }, 100); }); } function playIpad(){ iPadMovie(); } function stopIpad(){ clearInterval = interval; } You can see the fiddle here: http://jsfiddle.net/Vv2u3/15/ I

Clear all setIntervals

孤人 提交于 2019-12-05 11:20:52
I'm using setIntervals within an each() function like so $(".elements").each(function() { setInterval(function() { }, 1000); }); Obviously a setIntervals is created for each element. My question is: How do I clear all the setIntervals when I no longer need them? I have tried storing the setInterval in a variable and call window.clearInterval(int) , but that only clears the last setInterval since each variable is overridden. When you set an interval, you get a pointer to it: var myInterval = setInterval(function(){}, 4000); If you want to cancel an interval, you do the following: clearInterval

setInterval going too fast

你说的曾经没有我的故事 提交于 2019-12-02 01:10:31
I'm new to JS, and decided to start of learning by a making a small game. I am using a setInterval to automate the enemy's attack. For their first attack the interval is correct, but after the second attack it speeds up to attacking almost three times, or more, a second. I'm also having trouble stopping the interval once either the player's or the enemy's health reaches 0. here is pretty much all the code pertaining my problem. The whole code can be found here function deadFunct(){ if(yourHealth <= 0){ window.alert("You dead"); clearInterval(fightAuto); clearInterval(deadAuto); } if

Display Loading Animation Spinner while Loading Page

社会主义新天地 提交于 2019-12-01 14:19:13
I want to show loading animation spinner in a JQueryMobile page which is loaded w/ ajax off. The page is loaded with data-ajax="false" or rel="external" I tried on pagebeforecreate and pageshow event but its NOT working as I expected: $( '#page' ).live( 'pagebeforecreate',function(event){ $.mobile.loading('show'); }); $( '#page' ).live( 'pageshow',function(event){ $.mobile.loading('hide'); }); There's a slight problem with your request. First, you will not be able to show/hide ajax loader without set interval. There's is only one situation where this is possible without and that is during the

setinterval() and clearinterval() - when cleared, does not animate automatically

三世轮回 提交于 2019-11-30 16:03:20
问题 So I'm trying to build an animating background image which will cycle through an array of images. The idea is also that when you click any navigation element on the page, the cycle will pause. When you click on the home button, the cycle is to start up again (from the current image). This works in it's current state, however the cycle is not automatic upon re-firing it, instead you have to press the home button for each fade/slide/whatever. The script is as follows: $(document).ready(function

Javascript setInterval function to clear itself?

荒凉一梦 提交于 2019-11-29 22:04:50
myInterval = setInterval(function(){ MyFunction(); },50); function MyFunction() { //Can I call clearInterval(myInterval); in here? } The interval's not stopping (not being cleared), if what I've coded above is fine then it'll help me look elsewhere for what's causing the problem. Thanks. EDIT: Let's assume it completes a few intervals before clearInterval is called which removes the need for setTimeout. As long as you have scope to the saved interval variable, you can cancel it from anywhere. In an "child" scope: var myInterval = setInterval(function(){ clearInterval(myInterval); },50); In a

Can clearInterval() be called inside setInterval()?

空扰寡人 提交于 2019-11-29 21:59:05
bigloop=setInterval(function () { var checked = $('#status_table tr [id^="monitor_"]:checked'); if (checked.index()===-1 ||checked.length===0 || ){ bigloop=clearInterval(bigloop); $('#monitor').button('enable'); }else{ (function loop(i) { //monitor element at index i monitoring($(checked[i]).parents('tr')); //delay of 3 seconds setTimeout(function () { //when incremented i is less than the number of rows, call loop for next index if (++i < checked.length) loop(i); }, 3000); }(0)); //start with 0 } }, index*3000); //loop period I have the code above and sometimes it is working, sometimes it is

Javascript setInterval clearInterval Simple Example Not Working Explained?

烂漫一生 提交于 2019-11-29 12:13:13
I have a very simple JS setInterval and clearInterval example that doesn't work. There has got to be an underlying reason why it does not work and I would like to know why that is: var automessage; function turnON() //executed by onclick event A { var automessage = setInterval(function(){ something() }, 2000); } function turnOff() //executed by onclick event B { clearInterval(automessage); } function something() { //pulls instant messages } In this example, an end-user clicks a button to start a timed interval process, clicks another button to stop the timed interval process, and then clicks

How to stop a timer function from running?

左心房为你撑大大i 提交于 2019-11-29 10:56:18
I'm a bit new to js and have been trying to figure out how to stop this function from running when I click on a button. I tried using clearInterval but I am not sure I am doing it properly. Can someone take a look at this code and point me in the right direction? Code: <div><h1 id="target"></h1></div> <button id="stop">Stop</button>​ Script: var arr = [ "one", "two", "three"]; (function timer(counter) { var text = arr[counter]; $('#target').fadeOut(500, function(){ $("#target").empty().append(text).fadeIn(500); }); delete arr[counter]; arr.push(text); setTimeout(function() { timer(counter + 1)

Javascript setInterval function to clear itself?

假如想象 提交于 2019-11-28 18:18:59
问题 myInterval = setInterval(function(){ MyFunction(); },50); function MyFunction() { //Can I call clearInterval(myInterval); in here? } The interval's not stopping (not being cleared), if what I've coded above is fine then it'll help me look elsewhere for what's causing the problem. Thanks. EDIT: Let's assume it completes a few intervals before clearInterval is called which removes the need for setTimeout. 回答1: As long as you have scope to the saved interval variable, you can cancel it from