Menu
  • HOME
  • TAGS

Javascript element.style.opacity is undefined. Why?

javascript,element,setinterval,opacity

Try this Element.prototype.startFlicker = function() { var self = this; var blinkInterval = setInterval(function() { if (parseInt(self.style.opacity) === 0) { self.style.opacity = 1; } else { self.style.opacity = 0; } }, 50); }; In setInterval this refers to window, you need store context (this - current element) in variable and...

setInterval refuses to run my function after recent edit to my code… why?

javascript,node.js,setinterval

The reason why the code wasn't executed is because the functions were assigned to a variable so they weren't run until it got to setInterval. When they reach setInterval the errors prevent setInterval from executing (depends on the severity of the error). after taking the function and just running it...

Do not run function until condition is met

javascript,setinterval

Add the check in the success callback of your ajax request(s). This is better than using an interval. var check = function (maxValues, incrementValues) { if (maxValues == incrementValues) { runFunction(); } }; $.get( "example.php", function(data) { // Ajax successful check(data.maxValues, data.incrementValues); }); Or as @TedHopp suggested, use the always...

How to periodically update a variable using meteor

javascript,meteor,setinterval

Although you are using a reactive variable, it only gets set once - when the helper is first called. Therefore it doesn't run again. You need a function outside of the helper to set the session variable for you. Remember one important rule - helpers should never have side effects....

JQuery.get() halting setinterval after first request

jquery,setinterval

Yup. It will surely hang there, I'd be surprised if it didn't crash. What you're doing is you're creating a new request every half second So by 20 seconds you will have created 40 requests. It has to send a request, wait for it to respond, process it and while...

How does javascript setInterval and setTimeout 'threads' works?

javascript,jquery,settimeout,setinterval,timing

// (A) var t = $(this).addClass("extra-class"); //I'm sure I've added extra-class // (B) // Some long action here that could take more than 10ms ... // (C) // can I still be sure now that "this" still has class "extra-class"? Yes. Since JavasScript is single-threaded, there's only one thread that...

JavaScript multiple intervals and clearInterval

javascript,setinterval,clearinterval

You're assigning multiple interval IDs to the same variable which will only hold the interval ID that was assigned to it last. When you clear the interval, only the interval corresponding to that ID will be cleared. A straightforward solution would be to maintain an array of interval IDs, and...

setInterval doesn't work properly

javascript,setinterval

Your problem is that each click ADDS an interval. So your code basically runs more times than you want (making your animation faster). Make sure to clear the interval before starting a new one. Try the following (docs): window.myTimer = ''; function init() { function draw1() { context.clearRect(0,0,400,600); img_y =...

Javascript setInterval: multiple intervals

javascript,canvas,setinterval,clearinterval

This is just a guess, since is a bit hard to tell what is going on with only part of the code, but could it be that you are assigning currnetLoc twice, and thus the first player's location will always be always be compared against p2Loc[0]? So when you call...

JQuery - Image player issue

javascript,jquery,setinterval,player,timing

I think using 3 different timers is making this unnecessary difficult. If you refactor it into 1 unified timer, pausing (and other playback controls) would be quite easy. Separate your keyframe events into separate functions: function setImage(img) {...} function showTouch(x, y) {...} function hideTouch() {...} On startup, convert your screens...

What is the error with this tampermonkey code?

javascript,setinterval,tampermonkey,clearinterval

You problem is, there are multiple setInterval calls, looks like 3 on my end. If you run this code in your console before clicking "Start Game", it will log the following calls to setInterval. var originalSetInterval = window.setInterval; window.setInterval = function(func, intr) { var id = originalSetInterval.apply(window, arguments); console.log('----setInterval----'); console.log('function:',...

How to call setinterval function in another function is not working

javascript,jquery,setinterval

You have set async: false. So the ajax call will process synchronized. Set it to false or leave it out (because true is default): var clear_Process = ""; function updateRecords() { clear_Process = setInterval(function(){displayWaitingRecords()},200); var str = jQuery("#rrq_form :input[value!='']").serialize(); jQuery.ajax({ async: true, type: 'POST', data : str, url: "/updaterecord_status.php", success:...

value from ajax request not available

javascript,ajax,setinterval

Your function getStartingMissedJobs retrieves and sets the value of the missedJobs input asynchronously to the rest of your code. That means the line: var startingMissedJobs = $('#missedJobs').val(); will get evaluated whilst the request is in progress, so unlikely to get the proper value. One way to solve this would be...

setTimeout() inside setInterval() sequence fires off only once

javascript,settimeout,setinterval

This line : setInterval(updateOdometers(odometers), 2000); should be setInterval(function () {updateOdometers(odometers);}, 2000); Otherwise you will be calling updateOdometers(odometers) and passing its result to setInterval....

How to go about making a timer that counts down from 5 minutes and then redirect? JQuery

jquery,redirect,timer,setinterval,countdown

This should get you what you are looking for. One thing to remember with this solution though, setTimeout isn't guaranteed to fire exactly at 1000 milliseconds so your timer may occasionally be off by a little bit. (function() { var timer = 301; // 5 minutes worth of seconds +...

setInterval javascript - how to call function

javascript,setinterval

In the first example, where you have setInterval(displayNumber(), 500); you are calling displayNumber directly, instead of passing it as parameter. In fact, using setInterval(displayNumber, 500); should be sufficient (notice the lack of (), so that it is not called but rather passed as parameter)....

JQuery setInterval with pause on hover

jquery,hover,setinterval,fade,clearinterval

try this var timer; $(document).ready(function(){ timer = function(){$('#quotes > :first-child').fadeOut().next('div').fadeIn().end().appendTo('#quotes');}; $('#quotes .textItem:gt(0)').hide(); var interval = setInterval(timer , 2000); $('#quotes').hover(function (ev) { clearInterval(interval); }, function (ev) { interval = setInterval(timer , 2000); }); }); DEMO HERE...

How to join setInterval and .on(“click”) function together?

javascript,jquery,html,slider,setinterval

Here is an updated snippet that removes the jumpiness. Basically the issue was in the ".appendTo('.list');", which reordered the list items and made it difficult to continue the rotation once a bullet was clicked. The code significantly changed to get around this, but it should be more efficient since the...

How to create an accurate timer in javascript?

javascript,time,setinterval

Why is it not accurate? Because you are using setTimeout() or setInterval(). They cannot be trusted, there are no accuracy guarantees for them. They are allowed to lag arbitrarily, and they do not keep a constant pace but tend to drift (as you have observed). How can I create...

Reason to clearInterval before window unload?

javascript,browser,compatibility,setinterval

As mentioned in the comments, this code was added to History.js for compatibility with Env.js. Env.js is a headless browser written in JavaScript that is no longer under active development. So this is definitely an edge-case, to say the least. I'm guessing this issue is caused by a limitation of...

Stop setInterval until action not performed?

javascript,jquery,setinterval

try the below code. this may work, var flag = 1; jQuery('.product').on('mouseover', function(){ if(typeof timer != "undefined") clearInterval(timer); timer = setInterval(function() { if(flag){ if (counter === product_images.length) { counter = 0; } loading_image.removeClass('hidden'); selector.attr('src', 'localhost/product/' + product_images[counter]); flag = 0; var loadImage = new Image(); loadImage.src = selector.attr('src'); loadImage.onload =...

Div with id exists but not recognised by jQuery

javascript,jquery,setinterval

You don't need setInterval at the first place. All you need to do is to wait for the first load to complete, in the complete callback, do a setTimeout which would reload the div with the set delay. Hope that helps. $(document).ready(function() { //Store the reference var $elem = $('#wallboard');...

Will the code below clearInterval be executed inside setInterval?

javascript,function,setinterval

As far as I see the alert('333'); will appear exactly one time upon execution of the code above (you can test it in the console). Am I right? Yes, you're right. The first call to the callback clears the interval, and then the code continues and does the alert....

Javascript - setInterval()

javascript,setinterval

The browser is (or better: should be) clever enough to fully clean up a closed website. That includes aborting it's running connections and terminating scripts. The most that stays after you close the tab are the cookies and cached data

Using timer behind multiple alerts and prompts

javascript,setinterval

Here is my workaround: This code is called before the prompt is started: function initTime() { var now = new Date(); stS = now.getSeconds(); stM = now.getMinutes(); stH = now.getHours(); } This is called after the prompt is done: function computeTime() { var now = new Date(); var reS =...

Can anyone help me with why .substring() isn't working with setInterval roll out text?

javascript,html,substring,setinterval

You remove the default text so you can not increment the next letter since it no longer exists. So store a reference to it. var pHidden1 = document.getElementById("roll1"); if (!pHidden1.myDefaultText) { pHidden1.myDefaultText = pHidden.textContent || pHidden.innerText; } var text = pHidden1.myDefaultText; pHidden1.innerHTML = text.substring(0, tally); ...

escape from setInterval at end of game level

javascript,html5,canvas,setinterval

To stop a setInterval() you have to store the returned value from the original call to setInterval() in some persistent location and then call clearInterval() on that value. Because you declared your interval with var as in var int, it was local only to that method and was not available...

Image array won't draw to canvas

javascript,canvas,setinterval

It's hard to say exactly where you made a misstake. It seems like ALL your images are added at the same time the first time loadImg is called. In order for your example to draw the images with a delay, you need to put a delay on adding the actual...

Prevent user from calling clearInterval manually

javascript,jquery,setinterval,clearinterval

While you could trap the variable you store setInterval's return value in a closure to make it harder to inspect a user could still: Access it via a debugger Guess the value (it is just an integer) So, the short answer is that you can't. What happens in the user's...

Accessing “this” in asynchronous callback function in JavaScript

javascript,asynchronous,callback,this,setinterval

Javascript runs on a single thread. When you set fn to run on an interval, you accessed a DOM Api that acts in an asynchronous way (even though it isn't actually asynchronous.) What happens is the DOM api will insert a callback into the callback queue every time interval is...

Javascript clearInterval works only for one setInterval on page

javascript,jquery,setinterval,clearinterval

It's probably not a scope problem in this case, but that the reference IDs are overriden by several calls to order(). IDs are unique and the setInterval which run in the background has to have its id clear. If order() is called there is a risk of the old id...

Infinite setInterval even though it should've cleared?

javascript,canvas,setinterval

So, essentially when you have: i = setInterval(function () { i is undefined. As in, it doesn't even exist. So when you get to this part clearInterval(i); It says, i? What's that? Now I think JS has some capability to where it would derive that i is a variable, but...

Javascript easy timer does not work

javascript,timer,setinterval

There are several problems with your code you need to address: You need to make the clock variable global. In your example, an empty new variable clock is created each time the timer() function is called. You are using the clearTimeout() function instead of the clearInterval() function. The setInterval() function...

Random number not updating in SetInterval function

javascript,jquery,arrays,random,setinterval

Seems to me you are calling the actual function only once and then assigning it to randomColor which gets used over and over. What you should do instead is call it where it is needed: var drawFunc = drawBox.lazylinepainter({ "svgData": pathArray[i], "strokeColor": randomFrom(colors), "strokeWidth": 5, "responsive": true, "onComplete": drawLoop });...

clearInterval is not destroying setInterval timer

javascript,jquery,setinterval

you are no returning from the getimageRotatorFunction() var imageRotator; var getImageRotator = function() { if (imageRotator) clearInterval(imageRotator); // <-- not working it would seem? return setInterval(function() { $('.imageRotator').animate({opacity: ($('.imageRotator').css("opacity") == 1) ? 0 : 1}, 500); }, 9000); }; Now you can simply do this imageRotator = getImageRotator(); ...

setInterval() does not work on style.marginLeft

javascript,setinterval

You need to add 20 extra pixel every iteration setInterval(function(){ push(); },500); function push(){ var box = document.getElementById('box'); box.style.marginLeft= parseInt(box.style.marginLeft||0) + 20 + "px"; } #box{ background-color: green; width: 200px; height: 200px; } <div id="box"></div> ...

Trouble with setInterval in an object's method

javascript,setinterval

When you use var myCountdown = Object.create(countdownTimer); inside of your click function callback you are scoping it only to that callback and once the callback has executed it is garbage collected. You need to only create one instance of the countdownTimer, and it should be outside of your click event...

Stop simple JavaScript slideshow after one loop

javascript,jquery,slideshow,setinterval

Ok I have made this with the objective of being as clear and simple for you to understand as possible, (since you new to js...) JS/Jquery: $(function () { setTimeout(playSlideShow, 3000); function playSlideShow() { var currImgContainer = $('.showImg'); if (!$(currImgContainer).hasClass('lastImg')) { $('.showImg').removeClass('showImg').next().addClass('showImg'); setTimeout(playSlideShow, 3000); } } }); So here we...

Javascript | Callback to clearInterval, possible?

javascript,setinterval,clearinterval

The AJAX request is being made before the interval is cleared, so it's queued, and both end up being executed. You can add a check to see if the interval has been cleared with a bit of extra code: var id; id = setInterval(function() { $.get( 'https://example.com?dir='+myaddress,{}, function(data) { if...

setinterval and incremential value

javascript,scope,setinterval

This does exactly what you want: <body onload=""> <script type="text/javascript"> function defilementNouvellesOffres(){ var SELF = {} SELF.div1 = "nouvelleoffre_"; SELF.timer = 1; this.defilementNouvellesOffresTimer = function(){ Effect.Fade( SELF.div1 + SELF.timer, { delay : 2 }); SELF.timer++; Effect.Appear(SELF.div1 + SELF.timer, { queue: 'end' }); } this.startInterval = function(){ SELF.timerdefilement = setInterval("my_timer_function.defilementNouvellesOffresTimer();", 2000);...

Inappropriate use of setInterval

javascript,setinterval

So as I'm understanding your question and comments, you want to print something like this: you are here: 2 seconds you are here: 3 seconds you are here: 4 seconds I would recommend doing something like this: <html> <head> <script type="text/javascript" language="JavaScript"> var inter; var seconds = 1; function recharge()...

JavaScript timer | Random behavior

javascript,timer,settimeout,setinterval,oracle-adf

function displayOnTimeOut() { window.docTitle = document.title; var outputText = AdfPage.PAGE.findComponent('root:popupTxt'); outputText.setValue(' '); var timerInitDate = new Date(); var endTime = new Date(timerInitDate.getTime() + 5*60000) function displayCountdown() { var timeNow = new Date(); var timeleft = endTime - timeNow; if (timeleft <= 0) { clearInterval(timerIntervalId); window.onbeforeunload = null; outputText.setValue(' '); window.location.href...

setInterval executes only once

javascript,setinterval,anonymous-function

First problem, Element.node.style is not reliable. To check for current states and values, always use window.getComputedStyle( Node ). Second problem, css properties are represented in Strings, you cannot operate with math operators like +=. el.style.opacity = parseFloat( getComputedStyle( el ).opacity ) + 0.001; ...

Socket.IO - setInverval every two minutes (Node JS)

node.js,socket.io,setinterval

The code in io.on("connection", function(socket) { something(); }); is called for EVERY connected user, if you put a loop in this, the loop will loop paralelly for every connected user. The setInterval should be outside of your io.on("connection", function(socket) { });, and it will run once, from your node server...

Strange behavior for clearInterval in coffeeScript (not in scope?)

javascript,coffeescript,setinterval,clearinterval

_counter variable is defined inside iGetCalledOnEvents function and is deallocated as soon as function returns. So, you can do: _counter = null iGetCalledOnEvents = -> ... ...

Glow effect using snap svg

javascript,svg,setinterval,snap.svg,glow

I'm going to show a slightly different way of doing a filter, which I think should work for any filter, as you can just dictate it via normal svg markup which then opens up a few more filters that you may find out there on the internet to use. So...

AS3 About timers and loops

actionscript-3,timer,setinterval,flash-cc

You have a lot of options. For example: you can add 2 seconds in timeline of animation and listen for animation end. Or you remove for loop and start timeout after each step. Something like this: Write a method which will make the decision for current step: function MakeDecision() {...

Javascript:: Is audio.pause reset audio.currentTime value to 0?

javascript,function,audio,setinterval,addeventlistener

it is going back to the beginning because of this line, audio.src="Nadav Guedj - Golden Boy (Eurovision 2015 - Israel - Karaoke).mp3"; remove that, then audio.play would continue from where you paused. fiddle demo...

Javascript how to start script on exact time

javascript,loops,time,setinterval

I'd use the getTime object in JS I believe I have the time set right in this JSFiddle var d = new Date(); var year = d.getFullYear(); // Month 0 = January | Month 11 = December | so I changed vallues by +one var month = d.getMonth() +...

jquery stop setIterval [duplicate]

jquery,setinterval

You clear it inside a timeout $(document).ready(function () { $('button').click(function () { var interval = setInterval(function () { var firstdiv = $('.roll div:first'); var lastdiv = $('.roll div:last'); firstdiv.insertAfter(lastdiv); firstdiv = firstdiv.next(); }, 100); setTimeout(function() { clearInterval(interval); }, 5000) }); }); FIDDLE...

setInterval or setTimeout with String in JavaScript

javascript,settimeout,setinterval

setInterval() and setTimeout() return timer IDs. These help the browser recognize them again if you clear them, but you don't need to worry about their specific values. The function/code that is run has nothing to do with the return value of setInterval() or setTimeout(). The return value of the code,...

How can I loop a function?

javascript,loops,setinterval

jsBin demo Simply remove your inner fn function number_string() { cause you're not calling int anywhere. Also cache the elements you plan to reuse multiple times. var x = -1; var disp1 = document.getElementById("display"); var disp2 = document.getElementById("display2"); function z1() { setInterval(function y() { disp1.innerHTML = ++x; var number =...

jquery setTimeout too much recursion

javascript,jquery,recursion,settimeout,setinterval

You should indeed switch to setInterval() in this case. The problem with setInterval() is that you either have to keep a reference if you ever want to clear the timeout and in case the operation (possibly) takes longer to perform than the timeout itself the operation could be running twice....

How to implement a for-loop with unique setInterval variable names?

javascript,html,for-loop,svg,setinterval

You might encounter the issue with the context. We shall not create function inside the for loop :) for more information you can refer to this > https://jslinterrors.com/dont-make-functions-within-a-loop. So as work around, do something like this? http://jsfiddle.net/Lrhxbc5c/ var intervals = []; var getSetIntervalFunc = function (ii) { return function ()...

setTimeout is executing fast in IE

javascript,internet-explorer,firefox,settimeout,setinterval

I'm going to guess that this is a race condition and suggest that maybe this is a better way to achieve the same thing: $('document').ready(function() { var i = 1, data = 10; my_int = setInterval(function () { if (i <= data) { $('p').text(i++); } else { $('body').append("overflow").append("done"); clearInterval(my_int); }...

XMLHttpRequest() SetInterval

javascript,ajax,xmlhttprequest,setinterval

You need to do jsonrequestIntervaled.send();to make the call

jQuery button response time issue while auto refreshing a DIV in every X second

php,jquery,database,setinterval

After my whole researches I started to try all different options. And it only was OK when I change the jQuery code like this: setTimeout('sensorcells_load()', 10000); function sensorcells_load() { jQuery('#sensorcells').load('dashboard_content.php'); setTimeout('sensorcells_load()', 10000); } I am not a jQuery man and I don't really know why this one works but other...

Instantiating a class and then pass it to setInterval

javascript,scope,setinterval

The workaround would be: wrap it using another function instead of calling method directly function doKeyDown(e){ var instance = new Class(e.keyCode); setInterval(function(){ instance.functionToBeExecuded() }, 200); } This would give output many of these: Class {functionToBeExecuded: function} ...

Use setInterval to infinitely draw rectangles

javascript,canvas,setinterval,animated,rect

You can do it two different ways: You can continue to use rect() and stroke(), but you need to call beginPath() beforehand. When you call methods like rect(), a list, called the "path," is kept of all of the shapes, or "subpaths," that you've created. Then, when you call stroke(),...

JavaScript - Is it possible to modify the behaviour of setInterval/setTimeout used by third party scripts (externally hosted)

javascript,timer,setinterval

Well, I'd try to avoid this at all cost (except to try "for fun"). Here may be the result (a setInterval where all intervals >= 100 seconds are replaced by 100 seconds) // above the use of setInterval by third party code (function (w, maxVal) { var f = w.setInterval;...

Move ball inside border of Div

jquery,html,setinterval

The way you handle the boundary condition is not robust. If the ball finds itself more than velocity_y pixels beyond either boundary, then the velocity will just keep reversing on every frame, and the ball will get stuck vibrating in outer space (which you can actually see happening in your...

Image refreshing with setInterval()

javascript,jquery,html,settimeout,setinterval

I'd opt for a single timer that loops through all images. Then when the timer isn't needed anymore I can just discard the single timer. var timer = setInterval(swapImages, 2000); function swapImages() { $(.div-id option:selected).each(function(){ $(.div-id img).attr("src", "new-source-path"); }); } // some time later clearInterval(timer); PS. I assume that your...

setInterval() loop still running after clearInterval() is called

javascript,jquery,setinterval,clearinterval

1.- data in $.get is a String by default https://api.jquery.com/jquery.get/ data = parseInt(data) 2.- You add a second level of sync... Are you sure that this request is faster than 3000ms? 3.- If the data is > 99, the code works. In my concern, the problem is the request is...

What does (int)10000/1000 do in php?

javascript,php,setinterval

This: (int)$milliseconds/1000; is basically the same as: floor($milliseconds/1000); The result of the division is a float value. (int) turns it into an integer and cuts the decimals....

Make a timer using setInterval()

javascript,jquery,setinterval

function timer(seconds, cb) { var remaningTime = seconds; window.setTimeout(function() { cb(); console.log(remaningTime); if (remaningTime > 0) { timer(remaningTime - 1, cb); } }, 1000); } var callback = function() { console.log('callback'); }; timer(90, callback); Caution in using setInterval, may not work as you expect http://bonsaiden.github.io/JavaScript-Garden/#other.timeouts...

JavaScript setInterval and setTimeout timing issue [duplicate]

javascript,settimeout,setinterval,timing

setInterval and setTimeout may not be precise due to their design. They are executed by the browser engine, which means the browser can throttle them in some cases. Just for an example, if your browser just uses one process for the JavaScript, they can be throttled or maybe elapse more...

How to evenly time fading transitions?

javascript,jquery,callback,setinterval,fade

Here is the doc for .fadeOut() There is an optional argument complete: A function to call once the animation is complete. Put the next animation in there, they too take a complete (callback) function. $("#id").fadeOut(fadeTime, function() { // code to execute after animation complete }); ...

Javascript div fade in not working using setInterval

javascript,html,css,setinterval,fadein

To set your movies var, you need to call: document.getElementById('movies'); The way you are attempting to increment opacity didn't work, so I've updated your example. New Code: var movies = document.getElementById("movies"); var opacity = 0.1; var apparence = function(){ if(opacity <= 1.0) { movies.style.opacity = opacity; } else { clearInterval(timer);...

How to loop iframes using jquery?

jquery,loops,iframe,settimeout,setinterval

You can perform this action using recursion function and pass the arguments $('#iframe2').hide(); animateInfinite('#iframe', 1) function animateInfinite(str, last) { $(str + last).show(); setTimeout(function () { $(str + last).hide(); animateInfinite('#iframe', ((last == 1) ? 2 : 1)); }, 8000) } Or use setinterval var iframe = $('[id^=iframe]').hide(); iframe.eq(0).show(); setInterval(function () {...

Increment from zero to number in a set time

javascript,math,setinterval,increment

As @Mouser pointed out, the issue is that the animationInterval can't be too small (the actual minimum threshold will vary based on the browser and platform). Instead of varying the interval, vary the increment to the counter: var counterElement = $(".lg-number"); var counterTotal = parseInt(counterElement.text()/*.replace(/,/g, "")*/); var duration = 1000;...

How do I set the interval in a for loop?

javascript,for-loop,setinterval

You should have a look at CSS transitions. Basically you just need to change the right style from 300px to 0px and using transition: right 1s; you would see your element being animated https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_CSS_transitions Otherwise, you could have a look at jQuery.... (I feel bad)....

Unable to update the visibility of an html
block from ajax/jquery/JavaScript containing clearInterval/setInterval [closed]

javascript,jquery,ajax,setinterval,clearinterval

I added the fix to http://jsfiddle.net/20dw5ex8/6 use jquery show() and hide() functions. Like $('#export-div').show(); or $('#export-div').hide(); you can set your div hidden at the beginning <div id="export-div" hidden> Click Me</div> and show it when the ajax call is returned....

How to create a function setInterval with clearInterval inside it?

javascript,setinterval,clearinterval

setTimeout is prefered here. But you can use setInterval like this.. function refreshToHomePage3(handle,waitime){ handle = setInterval(function () { $('.wrapper').html(divResp); $('body').append(js); clearInterval(handle); }, waitime); return handle; } Actually there is no need to pass a handle variable into the function. function refreshToHomePage3(waitime){ var handle = setInterval(function () { alert("called after waitime");...

just can't make clearInterval() works

javascript,jquery,setinterval,clearinterval

Thank you guys, it seems I miss the basic thing and just tried to make things difficult on my own. I've combine all you guys' opinions, and get it works now. function bear_shake rewrite as below: function bear_shake(bool){ if(bool){ var i = 2; animation = setInterval(function(){ if(i % 2== 0){...

Modifiy class attribute inside Meteor.setInterval function

javascript,meteor,setinterval

this always refers to the current scope so you need to assign it to another var (ex self) if you're nesting functions: TestClass = function(){ this.left =10 var self = this; this.finterval = function(){ console.log("this.finterval:"+JSON.stringify(intervalId)) self.left = self.left -1 Meteor.clearInterval(intervalId) } var intervalId = Meteor.setInterval(this.finterval,1000) console.log("this.intervalId:" + this.intervalId) } ...

JavaScript setInterval for animation

javascript,animation,setinterval

Put the code in an anonymous function like this: <body onload="setInterval(function(){anim(document.getElementById('test'), 'left', 'px', 140, 300, 500)}, 500)"> ...

How can I create multiple setInterval()s dynamically? [duplicate]

javascript,for-loop,setinterval

You need to snapshot the value of i in a local scope otherwise it gets dynamically 'regenerated' at execution time, which means the value would then always be howMany, since the CPU lock, created by the main function, prevents your setInterval/setTimeout functions to execute before the loop is ended. for...

clearInterval when the setInterval has finished the whole execution

javascript,node.js,setinterval,clearinterval

You'll need to put your post-stopping code in a callback as well. You can check if this has been set before starting the next iteration, and then again inside your interval callbacks. var myVar; var stopCallback = null; var processing = false; function myFunction() { myVar = setInterval(function(){ processing =...

setInterval with php code

javascript,php,mysql,ajax,setinterval

Place your <?php?> code in a separate file, and call that file. I didn't look at the rest of your code to validate that it is "good", thought. You can't have serverside code perform on the client side, like that; nor do you want it to. Here is an example,...

Can't clearInterval on animation

javascript,jquery,jquery-animate,setinterval,clearinterval

You do not need setInterval at all.. var d1 = $(".drum1").data('end', true); function dani1() { if (d1.data('end')) return d1.stop(true, true); d1.animate({ height: '150px', width: '150px', opacity: '0.4' }, "slow") .animate({ height: '100px', width: '100px', opacity: '0.8' }, "fast", dani1); } d1.click(function() { if (!d1.data('end')) d1.data('end', true); else { d1.data('end', false);...

JS - pause play in setInterval

javascript,setinterval

In pls() you're asking for setInterval() to be called after 3 seconds. Calling setInterval() with no parameters will do nothing (although there should be an error in your JS console). You want to define your function once, then call it both when clicked, and at first run: var zman =...

jQuery execute multiple functions only on focus. 2 Problems

jquery,setinterval,onfocus

Maybe you need to call the function on .ready() (or .load()) too clearInterval() is called only on stuff2. Use different interval_id for both of them. Created a snippet for you: var interval_id; $(window).focus(function() { if (!interval_id) { interval_id1 = setInterval(stuff1, 1000); interval_id2 = setInterval(stuff2, 1000); } }); $(window).blur(function() {...

clearInterval not working after 6 time setInterval

javascript,counter,setinterval,clearinterval

Assign md to global variable:- var md; var d = [ "images/dado1.svg", "images/dado2.svg", "images/dado3.svg", "images/dado4.svg", "images/dado5.svg", "images/dado6.svg", ]; window.onload = function (){ dado.onclick = move; } function move() { md = setInterval(mudaDado,500); } function mudaDado(){ dado.setAttribute("src",d[time]); time++; if(time===6){ clearInterval(md); } } ...

setInverval runs only once

javascript,jquery,html,setinterval

Your triggerNextNewsitem() is running inside the initNews() function. Variable captions and firstNews etc. are declared inside the initNews before triggerNext, so every time triggerNext is run, it triggers click on the same element. Change your triggerNextNewsitem so you select the element to click every time. i.e. var triggerNextNewsitem = function...

Get a returned value from a simple setInterval function

javascript,function,setinterval

The purpose of setInterval is to execute a function every X milliseconds. In your original code, when the run function returns each time, its returning to the context of the native setInterval function. The setInterval function does NOT console.log it out for you automatically. When you run your code run();,...

setTimeout with condition inside before running again

javascript,jquery,settimeout,setinterval

Have a flag to indicate whether the timer has elapsed, and check that flag when you're handling mouse activity. var elapsed, timer; function refresh() { //... stuff you want to do ... resetTimer(); } function resetTimer() { if (!elapsed) { clearTimeout(timer); } elapsed = false; timer = setTimeout(function () {...

Javascript setInterval doesn't work correctly when tab is not active

javascript,jquery,setinterval

Use the Date object to calculate time. Don't rely on a timer firing when you ask it to (they are NOT real-time) because your only guarantee is that it'll not fire before you ask it to. It could fire much later, especially for an inactive tab. Try something like this:...

How could I en mass change divs in jquery randomly?

jquery,setinterval,opacity

You can use .each() to iterate through a set of elements like $('.point').each(function() { var $this = $(this); var myVar = setInterval(function() { $this.css('opacity', Math.round(Math.random())); }, 50); }) @import url(http://fonts.googleapis.com/css?family=Roboto+Condensed:400, 300|Roboto:400, 300, 100, 500|Dancing+Script:400, 700); .point { width: 10px; height: 10px; background-color: Black; border-radius: 5px; margin: 0px; display: inline-block; }...

From interval to requestAnimationFrame

javascript,animation,setinterval,requestanimationframe

You can bind the value of this using the bind() method function Rotation(mass) { this.mass = mass; this.angle = 0; this.velocity = 1; this.handler = null; this.rotate = function () { this.angle = (this.angle + this.velocity) % 360; var transform = "rotate(" + this.angle + "deg)" this.mass.elm.style.webkitTransform = transform; //call...

Variable undefined after setting interval

javascript,jquery,undefined,setinterval

this.Action is passed to setInterval as function w/o its context so this is not pointing to the instance of TEST any more but defaults to window. Try it like this: var TEST = { DIR: null, ITV: null, Init: function () { this.DIR = 1; this.Action(); }, Action: function ()...