settimeout

Setinterval with exponential time decrease

早过忘川 提交于 2019-12-23 10:16:15
问题 I've got a mousedown event with a setinterval. I want the time of intervals to be variable. So the first one is 500, the second one 500/2 = 250, etc. Any tips? $plus.mousedown(function(e) { increment(20) timeout = setInterval(function(){ increment(20) }, 500); }); $(document).mouseup(function(){ clearInterval(timeout); return false; }); Cheers! EDIT: sorry for the ambiguity. I want the time of interval to change during the mousedown. So while the mousedown is being performed the intervaltime

Is it safe to pass setInterval or setTimeout a fractional delay?

删除回忆录丶 提交于 2019-12-23 09:23:29
问题 I know that the difference would currently be negligible due to inaccurate browser timers, but for the sake of knowledge if nothing else: is there any browser that supports setInterval and setTimeout, but requires that they be passed an integer value as a delay? Or, rephrased with examples, is this: setInterval(animate,50/3); as cross-browser compatible as this? setInterval(animate,17); 回答1: It is perfectly safe. (As RobG points out, I haven't provide a reference to the DOM/JS bridge rules

can I have a setTimeout inside another setTimeout?

时光总嘲笑我的痴心妄想 提交于 2019-12-23 08:03:12
问题 Here's a quick (broke) jsfiddle: http://jsfiddle.net/wH2qF/ This isn't working for some reason... is it because I have a setTimeout inside another setTimeout? $(function() { $("#Volume").click(function() { setTimeout(triggerVolumeChange, 4000); function triggerVolumeChange() { var volumeDiv = document.getElementById("volumeNumber"); var volumeOld = 8; var volumeNew = 37; var timeNew = (1000/(volumeNew-volumeOld)); changeVolume(); function changeVolume() { volumeDiv.innerHTML = volumeOld;

Persist setTimeout and setInterval across Node.js restarts

瘦欲@ 提交于 2019-12-23 07:59:04
问题 I set quite a few server-side timeouts with setTimeout and setInterval for each connected user that can last for 10-30 seconds. If the Node.js instance restarts in the middle of one of these timeouts, they are obviously all cleared on restart, which can cause some issues for these users. How would I go about persisting these timeouts, or are there any modules that already help with this? 回答1: I would store the start times and durations in Redis and restart incomplete timers when your

Javascript how to stop setTimeOut

爷,独闯天下 提交于 2019-12-23 05:07:21
问题 Hellow I ran into a little problem i don't know how to stop my add function when it reaches some Y position on my web, can some body help me whit it!! var scroll = function(){ var positionYTop = 0, speed = 50, links = document.getElementsByTagName('a'); function timer() { var clock = setTimeout(add, 200) } function add() { window.scrollTo(0, positionYTop += speed); timer(); } add(); } 回答1: A common approach to this is to start off by setting the scroll in advance, along with a transform

Javascript how to stop setTimeOut

谁说我不能喝 提交于 2019-12-23 05:07:10
问题 Hellow I ran into a little problem i don't know how to stop my add function when it reaches some Y position on my web, can some body help me whit it!! var scroll = function(){ var positionYTop = 0, speed = 50, links = document.getElementsByTagName('a'); function timer() { var clock = setTimeout(add, 200) } function add() { window.scrollTo(0, positionYTop += speed); timer(); } add(); } 回答1: A common approach to this is to start off by setting the scroll in advance, along with a transform

Multiple XmlHttpRequests every x seconds

喜你入骨 提交于 2019-12-23 04:41:57
问题 i need some help on some code that i m writting.. my code fires three asychronous requests and updates some content on my page. i want these requests to be fired every X seconds.. i have seen several questions like this, how to schedule ajax calls every N seconds? regarding setTimeout or setInterval, but the issue is that i need each request to be fired every x seconds..while the only i can think of that setInterval / settimeout wouldn't count seperate time for each call, but just one time..

jquery settimeout and .focus() together not working in firefox browser

别说谁变了你拦得住时间么 提交于 2019-12-23 03:32:07
问题 I have a form which when submitted(empty fields) displays spring validated errors in the front end jsp . I need to focus the display in the first error message displayed in the front end. Generated code from the form (via view source): For example 2 error message enclosed inside div element. I need to focus it on the first error message. <div id="userid.errors" class="lp">User id is missing</div> <div id="age.errors" class="lp">age is missing</div> I tried the below jquery code, but it works

jquery settimeout and .focus() together not working in firefox browser

╄→гoц情女王★ 提交于 2019-12-23 03:31:22
问题 I have a form which when submitted(empty fields) displays spring validated errors in the front end jsp . I need to focus the display in the first error message displayed in the front end. Generated code from the form (via view source): For example 2 error message enclosed inside div element. I need to focus it on the first error message. <div id="userid.errors" class="lp">User id is missing</div> <div id="age.errors" class="lp">age is missing</div> I tried the below jquery code, but it works

Node.js script should wait before service is running

醉酒当歌 提交于 2019-12-23 03:22:57
问题 I have a node.js script which starts at boot. It uses node-redis to create a client for Redis, but at boot Redis is not ready while node is already starting. So, it gives an exception and stops executing. The first part looks like this: var redis = require("redis"), jobs = require("jobs"), client = redis.createClient(), runner = new jobs(client, "job-queue",{}); // Continue using runner The exception is thrown in line 3 ( redis.createClient() ). My solution was to make an endless loop, create