settimeout

Javascript setTimeout, Loops and Closure

房东的猫 提交于 2019-12-11 13:16:51
问题 The following code has me confused. My goal is to fade an HTML element from one opacity level to another, over a period of time. Below is my dimScreen() method, used to create a darkened overlay and fade it in. var overlay; function dimScreen() { if(!overlay) { overlay = document.createElement('div'); overlay.setAttribute('id', 'overlay'); overlay.style.width = '100%'; overlay.style.height = '100%'; overlay.style.zindex = '1000'; overlay.style.background = '#000013'; overlay.style.position =

Differentiating between mouseup mousedown and click

时光毁灭记忆、已成空白 提交于 2019-12-11 11:58:00
问题 I know that mousedown happens when a user depresses the mouse button, mouseup happens when the release the mouse and click is of course two events mousedown and mouseup. I have three different events each dealing with these three events mouseup down and click. My question is how to differentiate between the three, now my mouse down has a timer, so I was thinking of adding a boolean in that timer and testing it within the click I tried this and it didn't work to my standards. Mousedown- timer

setTimeout - Pass variable as time

孤街醉人 提交于 2019-12-11 11:24:12
问题 I have a setTimeout, and I want to be able to use a variable as the timer: var that = this; var time = this.spawnTime; setTimeout( function(time){ that.SpawnCounter(); }, time); This doesn't seem to do the trick. Any ideas why? Thanks 回答1: var that = this; var time = 1000; setTimeout( function(time){ that.SpawnCounter(); }, time); The code above should work. Maybe the problem is that this.spawnTime is not numeric or invaild. 来源: https://stackoverflow.com/questions/15559739/settimeout-pass

Help chosing between settimeout and setinterval

大憨熊 提交于 2019-12-11 10:08:40
问题 UPDATE 2: OK, looks like it runs the first time after a minute. How do I get it to run onload, then every minute after that? UPDATE 1: I've tried: var interval = setInterval(get_reported_incidents, 60000); but nothing happens. in get_reported_incidents(); I just have an alert("hello"); . ORIGINAL QUESTION: I want to run a function every minute: get_reported_incidents(); But I am not sure which method is best for this task; settimeout or setinterval 回答1: It's totally personal preference.

Using a loop to set multiple timeouts for a function

我的未来我决定 提交于 2019-12-11 10:07:55
问题 I'm using Moment.js to handle time. 10 Inning objects (durations) have properly been defined with start and end times, as shown in this question's JSFiddle. This script is meant to use the the difference between an Inning end time and the present to define the necessary Timeout to be set for a function endInning() to be called. This is implemented within a loop to handle the 10 Innings. for (x = 0; x < 10; x++) { // for each of ten defined innings // calculate the difference between the end

jQuery plugin, context and setTimeout

与世无争的帅哥 提交于 2019-12-11 08:49:16
问题 I'm writing a plugin for jQuery and I have a mess in my head with the context issue in javascript. This is a simplified version of my plugin: (function($){ $.fn.myplugin = function(options){ return new MyPlugin(this, options); }; function MyPlugin(el, o ) { this.root = el; this.input_box = el.find('#the_input'); this.map = null; this.timeout = null; var self = this; self.input_box.keyup( function(){ if( self.timeout!==null ) { clearTimeout( self.timeout ); } self.timeout = setTimeout(

Meteor.setTimeout function doesn't work

北慕城南 提交于 2019-12-11 08:36:08
问题 I've looked around the internet for quite a while trying to figuring out what's wrong with my code and couldn't find a working answer. Template.map.onCreated(function() { Meteor.setTimeout(function() { GoogleMaps.ready('exampleMap', function(map) { var marker = new google.maps.Marker({ position: map.options.center, map: map.instance }); }); }, 2000); }); I'm simply trying to set a 2 seconds delay for the GoogleMap function to trigger but it doesn't work. I've tried a lot of various things

Getting onBeforeUnload to work with a setTimeout

六月ゝ 毕业季﹏ 提交于 2019-12-11 07:55:13
问题 I am trying to get onbeforeunload to work with a set timer of sorts but I can't seem to get it to fire up when the return is in place. I am hoping it would work with a timer but for some reason the timer isn't working. Here is the code I am working and thank you for your help in looking at it much appreciated. var validNavigation = false; function wireUpEvents() { var leave_message = 'Leaving the page'; jQuery( function goodbye() { jQuery(window).bind('onbeforeunload', function() { setTimeout

Javascript - Wait the true ending of a function that uses setTimeout

眉间皱痕 提交于 2019-12-11 07:53:24
问题 Let me explain my problem with a dummy situation. Let's consider the following code : var counter = 0; function increase(){ if(counter < 10){ counter++; setTimeout(increase, 100); } } Now, the idea is to display the counter value once the increase() function has finished its job. Let's try this : increase(); alert(counter); As you probably know, it doesn't work. The alert() call displays 1, not 10. I would like to display the value of counter once the function has entierly finished its job of

Function is undefined?

喜你入骨 提交于 2019-12-11 07:44:03
问题 I'm struggling to find out why the setTimeout function cannot find my radio button tagging function when trying to run. this is my code... var radioButtonTagging = (function(){ console.log('run'); $("span.radio").each(function(i, ele){ $(ele).addClass('radio'+i); }); $(".radio1").click(function(){ console.log('fired'); $('#expandQuestion1').css('display','block'); }); }); if($('span.radio').length){ console.log('run'); radioButtonTagging(); } else { console.log('trying to run timer');