settimeout

Simple Countdown Timer Typescript

给你一囗甜甜゛ 提交于 2019-12-13 16:14:38
问题 I have the following code in my constructor: constructor(){ for (let i = 0; i < 90; i++) { setTimeout(() => { this.counter = this.counter - 1; }, 1000) } } What I actually want is to display a number which counts down 90 seconds. Right now it counts down from 90 to 0 immediately 回答1: You can use setInterval instead to make the function be called every 1 second until the counter reaches 0: class Timer { constructor(public counter = 90) { let intervalId = setInterval(() => { this.counter = this

Javascript setTimeout works on desktop, not on android?

£可爱£侵袭症+ 提交于 2019-12-13 15:24:27
问题 I have a function that plays an different audio file at random every n seconds (based on input from a web page) when the user hits start. As you would expect, it stops when they hit stop. It works fantastic on my desktop (using chrome), but I've tried it on two different android devices (note 4 and note 8) in chrome but it will only play the audio once before bailing. Workflow: User clicks start, the function startstop is called. If it's the start button, play the audio and create a timeout

node.js setTimeout resolution is very low and unstable

余生颓废 提交于 2019-12-13 14:54:46
问题 I got a problem with resolution of setTimeout. When I set it to 50 ms, it varies from 51 to even 80 ms. When I use sleep module, I am able to get resolution like 50 µs, so what is the setTimeout function problem to get at least 1 ms? Is there any way to fix/avoid that? The problem with sleep is that it delays everything even when callback function should be shoot, it waits... Is there an alternative solution to shoot some events in delay of exactly 50 ms? For example with sleep module: var

jQuery dropdown menu with setTimeout does not work

孤者浪人 提交于 2019-12-13 08:46:56
问题 I know this questions being asked many times already but I can not make my drop down menu work with what I have so far. The problem appears if I set delay for menu to show, without setTimeout the menu works just fine. Could anyone take a look and suggest the solution please? I am also trying that it works in IE6. Here is the full example with setTimeout: http://jsbin.com/owoyon/1/ (bugged, does not work correct, drop downs get stuck, delay is not recognized) here is a working version without

Make a div move using jquery

血红的双手。 提交于 2019-12-13 06:45:09
问题 I'm trying to make a div move of 50px from left to right every 500 milliseconds with the following jquery code: <div id="obj"></div> <script> function move(before){ var howmuch = before + 50; $("#obj").css("margin-left",howmuch + "px"); setTimeout(move(howmuch),500); } setTimeout(move(0),500); </script> #obj{ background-color:red; width:100px; height:100px; border-radius:10px 10px 10px 10px; -moz-border-radius:10px 10px 10px 10px; -webkit-border-radius:10px 10px 10px 10px; margin-left:0px; }

Make settimeout different depending on certain factors

时光毁灭记忆、已成空白 提交于 2019-12-13 06:32:07
问题 I'm trying to refresh a page, and every time I refresh the page, I want to roll a random number. If it's zero I want the page to wait 5 seconds before refreshing again. If it's one I want the page to wait 1 second before refreshing again? However, with my code, the page either refreshes after 1 second every single time, or it refreshes after 5 seconds every single time. What am I doing wrong, and how do I fix it? Please use the codes that I have, and point out what I did wrong in my code: //

JQuery setTimeOut while loop

前提是你 提交于 2019-12-13 06:05:55
问题 My brain its going to explode.. why this dont work? im trying to animate a few divs with time interval and trying to write less code but this dont work var cargaCont = function(){ o = 1; var animacion = function(i){ $('#page2txt'+i).animate({ height:'20' },200,function(){ $('#page2img'+i).animate({ left:'0', right:'0' },200,function(){ i++; return i; }); }); } while(o < 3){ setTimeout(function(){o = animacion(o);},200); } } 回答1: The problem with this code: while(o < 3){ setTimeout(function()

Execute a function after X seconds in jquery

痴心易碎 提交于 2019-12-13 04:39:08
问题 Instead of triggering code on click of the element, I want this function to run automatically after 4 seconds. How can I make it possible? $('a.close,form #okLogin, mask').live('click',function () { $('.login-popup').fadeOut(300); $('#mask').remove(); return false; }); 回答1: $(function(){ setTimeout(function(){ $('.login-popup').fadeOut(300); $('#mask').remove(); },4000); }); 回答2: setTimeout(function () { $('.login-popup').fadeOut(300); $('#mask').remove(); }, 4000); 回答3: Use the built in

jquery tools tooltip doesn't appear in first try after hide()

馋奶兔 提交于 2019-12-13 04:33:49
问题 I've used tooltip for a <div> It will hide() after couple of seconds If I'll mouse over it's trigger after it for the first time it will not appear only after I move the mouse over it the second time it will appear I used onShow event for binding and used window.setTimeOut is it a problem in the tooltip or in jquery? something like this: $(document).ready(function() { x = $("button").tooltip({ api: true, position: "center right", onShow: function() { var hid = function() { x.getTip().hide();

Using setTimeout To Delay A jQuery Animation

血红的双手。 提交于 2019-12-13 03:55:33
问题 I'm working on some out transitions on image when a user presses the button to move to the next image. When there are multiple images next to each other that are very narrow, those images will all transition at the same time. So I check the width on the images and add the thin ones to an array and then run the transition on each object in the array. I wanted to create a little delay between the animation of each image in the array so I'm trying to run my jQuery.animate after a 1 second