setinterval

Run set Interval again for every interval ID in array

只谈情不闲聊 提交于 2019-12-13 07:14:35
问题 I am currently storing a bunch of setInterval ID's in an array. How I initially set the intervals: intervalId = setInterval(bridgeCall, 10000); interValArray.push(intervalId); I currently have a button that enables me to stop all intervals currently running by calling this function: function stopCampaign() { if (interValArray.length > 0) { for (i = 0; i < interValArray.length; i++) { clearInterval(interValArray[i]); console.log("Stopped"); } error = "Stopped" Error(); } else { error =

execute a method on an existing object with window.setInterval

吃可爱长大的小学妹 提交于 2019-12-13 07:04:57
问题 Is it possible to run the method on an existing object on timeout of window.setInterval method. I can emulate the same by having some global variable and calling the method of this global variable in setInterval, but i wanted to know if this is possible using the method directly. Best Regards, Keshav 回答1: Yes, you can do this. You need a helper function to make a new function that has your existing object "bound": var someRandomObject = { someMethod: function() { // ... whatever }, // ... };

setInterval delays not accurate

若如初见. 提交于 2019-12-13 04:16:06
问题 I'm currently creating a countdown using setInterval though at the moment it runs slower than it should. According to the MDN, the delay parameter is in milliseconds however it isn't accurate. I compared my countdown to the one on my phone and the phone runs nearly 5 times faster. var count = setInterval( function() { if (iMil == 0) { if (iS == 0) { if (iMin == 0) { if (iH == 0) { // DONE } else { iH--; iMin = 59; iS = 59; iMil = 999; } } else { iMin--; iS = 59; iMil == 999; } } else { iS--;

Changing a global variable inside a function, to change the setInterval's second parameter [duplicate]

佐手、 提交于 2019-12-13 03:27:18
问题 This question already has answers here : Changing the interval of SetInterval while it's running (14 answers) Closed 4 months ago . I have a global variable called interval, and I need to change this global variable to 5000 inside a function, so after waiting for 1 second, the setInterval function will now wait for 5 seconds. However, when I tried the code below, it only waits 1 second every time it's executed. var timeToWait1 = 1000; var timeToWait2 = 5000; var interval = timeToWait1;

setInterval performance [duplicate]

本秂侑毒 提交于 2019-12-13 03:20:01
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Javascript: setInterval() behaviour with 0 milliseconds I simply want to hear, if it is a problem having a setInterval with time set to 0 milliseconds? Will there be any performance issues? And will it be better to have e.g. 1000 milliseconds? I have this script: var countdown_id = setInterval(function() { var now = (new Date()).getTime()-(2*60*60*1000); ; $('.product').each(function() { var elm = $(this).attr(

And yet another javascript clearInterval not working

坚强是说给别人听的谎言 提交于 2019-12-13 02:11:48
问题 I've seen a bunch of these threads and went through a few of them but nothing seemed to be of help so far. So I'm trying to call the timer continuously while the ajax call is taking place. Once the ajax call reaches the complete event, I'd like to clearInterval the timer, but that doesn't seem to be working because the call to CheckProgress() keeps going and going. Here's my code: var timer = ""; $("#ChartUpdateData").click(function () { $("#loadingimgfeatdiv").show(); //ajax loading gif if

simulating a synchronous XmlHttpRequest

限于喜欢 提交于 2019-12-13 02:08:35
问题 I've read some of the other related questions (Pattern for wrapping an Asynchronous JavaScript function to make it synchronous & Make async event synchronous in JavaScript & there may be more), but I just want to be sure to exhaust all possibilities. Might it be possible to "convert" an asynchronous XmlHttpRequest into a quasi-synchronous one using either setInterval or setTimeout? The idea being that upon success of the Ajax request a variable will be set, which will be the signal for a

Delay mousedown interval start (JQuery / Javascript)

半城伤御伤魂 提交于 2019-12-13 00:08:55
问题 I am writing a jQuery plugin that manipulates the value of an input field at the press of a button. What I have so far is the ability to control the value by clicking the button, as well as to continually increase it if the user holds the button pressed. Simplified, the script is something like this: var element = $('#test-input'); var interval; $('#test-up-button').on({ mousedown : function(e) { element.val(parseInt(element.val()) + 1); //Wait 400ms, than do the interval interval = window

Autoscroll with setInterval/clearInterval

笑着哭i 提交于 2019-12-12 15:00:08
问题 Im relatively new to JS coding, and can't get this little number to work. Can anyone tell me what I'm doing wrong? My JavaScript is: incrementScroll = function() { window.scrollBy(0, 3) ; } startScrollLoop = function() { scrollLoopId = setInterval( "incrementScroll", 5) ; } stopScrollLoop = function() { clearInterval( scrollLoopId ) ; } And my HTML is: <button onclick="startScrollLoop()">AUTO SCROLL</button> <button onclick="stopScrollLoop ()">STOP SCROLL</button> Again, many thanks for help.

setInterval only runs once on object method

偶尔善良 提交于 2019-12-12 13:28:37
问题 Here is the code. (function($){ $.fn.testfunc = function() { this.init = function() { setInterval(this.func1(), 1000); }; this.func1 = function() { console.log('func1'); this.func2(); }; this.func2 = function() { console.log('func2'); //some codes }; return this.init(); } })(jQuery); *When I use parenthesis the 1st and 2nd method runs but the 1st method is called only once. *When I don't use parenthesis the 1st method runs in interval just fine but it doesn't/couldn't call the 2nd method.