setinterval

Jquery setInterval too fast when coming from another tab

本秂侑毒 提交于 2019-11-27 22:22:31
I've got a site with endlessly sliding images using jquery's setIntervall() function. When calling the page in Chrome 13 and I switch to another tab to come back a few seconds later the image sliding is happening faster, as if it tried to keep up to where it was if it hadn't switched to another tab. How could I resolve this issue? $(window).load(function() { setInterval(nextSlide, 3500); }); function nextSlide(){ offset += delta; $("#slideContent").animate({left: -1 * offset}, 1000); } Solution: I chose jfriend00's first advise. Now I turn the timer off when the window becomes inactive. The

setInterval with loop time

▼魔方 西西 提交于 2019-11-27 20:28:49
setInterval(function(){}, 200) this code run the function each 200 miliseconds, how do I do it if I only want the function to be ran 10 times. thanks for help. Use a counter which increments each time the callback gets executed, and when it reaches your desired number of executions, use clearInterval() to kill the timer: var counter = 0; var i = setInterval(function(){ // do your thing counter++; if(counter === 10) { clearInterval(i); } }, 200); Esailija (function(){ var i = 10; (function k(){ // your code here if( --i ) { setTimeout( k, 200 ); } })() })() shadownrun if you want it to run for

How to start and stop/pause setInterval?

我们两清 提交于 2019-11-27 20:22:19
问题 I'm trying to pause and then play a setInterval loop. After I have stopped the loop, the "start" button in my attempt doesn't seem to work : input = document.getElementById("input"); function start() { add = setInterval("input.value++", 1000); } start(); <input type="number" id="input" /> <input type="button" onclick="clearInterval(add)" value="stop" /> <input type="button" onclick="start()" value="start" /> Is there a working way to do this? 回答1: The reason you're seeing this specific

How to periodically update a variable using meteor

大兔子大兔子 提交于 2019-11-27 18:32:51
问题 I have a session variable that I want to update with a fixed periodicity. Say, I want this variable to be increased by 1 every 60 seconds. It seems to me that the best place for doing this is inside the helpers section of the relevant template. I first tried to do this using setInterval as described here, but that didn't work (the function just didn't seem to repeat). I then tried what I thought would be a straightforward solution, but this also doesn't work. See below. The helper variable

Node.js crashes when using long interval in setinterval

回眸只為那壹抹淺笑 提交于 2019-11-27 15:34:22
问题 function createSasTokenTimer() { console.log("Hello"); } setInterval(createSasTokenTimer, 3000000); I run this code and after 50 minutes I get the following error: Hello timers.js:265 callback.apply(this, args); ^ TypeError: Cannot read property 'apply' of undefined at wrapper [as _onTimeout] (timers.js:265:13) at Timer.listOnTimeout (timers.js:110:15) When the interval time is shorter ( 2000000 for example), everything works fine. Is this a bug in Node.js? Update: OS: Windows , Node.js

Javascript setInterval not working

↘锁芯ラ 提交于 2019-11-27 11:15:06
I need to run a javascript function each 10 seconds. I understand the syntax must work like follow but I am not getting any success: function funcName() { alert("test"); } var func = funcName(); var run = setInterval("func",10000) But this isn't working. Any help? A lot of other answers are focusing on a pattern that does work, but their explanations aren't really very thorough as to why your current code doesn't work. Your code, for reference: function funcName() { alert("test"); } var func = funcName(); var run = setInterval("func",10000) Let's break this up into chunks. Your function

Does JavaScript setInterval() method cause memory leak?

馋奶兔 提交于 2019-11-27 11:05:27
Currently developing a JavaScript based animation project. I have noticed that, proper use of setInterval() , setTimeout() and even requestAnimationFrame allocates memory without my request, and causes frequent garbage collection calls. More GC calls = flickers :-( For instance; when I execute the following simple code by calling init() in Google Chrome, memory allocation + garbage collection is fine for the first 20-30 seconds... function init() { var ref = window.setInterval(function() { draw(); }, 50); } function draw() { return true } Somehow, within a minute or so, starts a strange

What is the equivalent of javascript setTimeout in Java?

一个人想着一个人 提交于 2019-11-27 10:47:09
问题 I need to implement a function to run after 60 seconds of clicking a button. Please help, I used the Timer class, but I think that that is not the best way. 回答1: "I used the Timer class, but I think that that is not the best way." The other answers assume you are not using Swing for your user interface (button). If you are using Swing then do not use Thread.sleep() as it will freeze your Swing application. Instead you should use a javax.swing.Timer . See the Java tutorial How to Use Swing

How to exit from setInterval

*爱你&永不变心* 提交于 2019-11-27 10:41:11
问题 I need to exit from a running interval if the conditions are correct: var refreshId = setInterval(function() { var properID = CheckReload(); if (properID > 0) { <--- exit from the loop---> } }, 10000); 回答1: Use clearInterval: var refreshId = setInterval(function() { var properID = CheckReload(); if (properID > 0) { clearInterval(refreshId); } }, 10000); 回答2: Updated for ES6 You can scope the variable to avoid polluting the namespace: const CheckReload = (() => { let counter = - 5; return () =

function in setInterval() executes without delay

≯℡__Kan透↙ 提交于 2019-11-27 09:33:34
I am in the process of making a jquery application to hide an image after a specified interval of time by using setInterval(). The problem is that the hide image function executes immediately without delay. $(document).ready(function() { setInterval(change(), 99999999); function change() { $('#slideshow img').eq(0).removeClass('show'); } }); I am testing it in jsfiddle . http://jsfiddle.net/wWHux/3/ You called the function immediately instead of passing it to setInterval . setInterval( change, 1500 ) - passes function change to setInterval setInterval( change(), 1500 ) - calls the function