setinterval

clearInterval before setTimeout wont work

China☆狼群 提交于 2019-12-08 13:35:24
问题 I have a problem with clearing an interval. I have 3 functions start1 , start2 , start3 . Here you can see only the first. The function count1 and variable myVar1 have the same princip they are the same numbered. Now the problem is that clearInterval only works after the first function (See console log). After the second start2() anything happens what I cant explain by myself. I made a demo. start1(); function start1() { var valuem = 0, dir = 1; $('#number').text(valuem); function count1() {

setinterval not able to run document.writeln

左心房为你撑大大i 提交于 2019-12-08 11:52:25
问题 Greetings, The code below works for alert but doesn't for document.writeln. Is it because of the onload event? If so shouldn't the browser be able to add more elements after it's finished loading? - Trying to understand how it works (I am studying jquery in the meantime). <body onload="timeMsg()"> <script type="text/javascript"> function timeMsg() { var t=self.setInterval("randInt()",3000); } function randInt() { document.writeln("<br />" +Math.floor(Math.random() * 7)); //doesn't work alert

jQuery auto refresh page on clock time

送分小仙女□ 提交于 2019-12-08 10:40:09
问题 How do I refresh the page automatically every 15 minutes based on clock time? For example: refresh on 9:00, 9:15, 9:30, 9:45, 10:00, 10:15, so on.. I have seen one similar like I wanted : https://stackoverflow.com/a/1217945/551559 but I don't think it does the job. setInterval(function(){ // check clock time on every minute?? if ( clock_time === '9:15' ) { } },1000); Can someone give me a solution or any link to look at? 回答1: setInterval(function(){ var minutes = (new Date()).getMinutes() if

Temporary changing the time of setInterval

我怕爱的太早我们不能终老 提交于 2019-12-08 09:33:42
问题 The timing value in setInterval determines the next time at which the function is going to be invoked again. For example: t = 8000; myFunction(){ if (someCondition){ //halt setInterval //t = 5000; // setInterval(myFunction,t); } // do some logic } setInterval(myFunction, t); The problem is changing of t will not affect the time that I want the current call to be remained before the next call. In other words, is there any way to halt setInterval and then I can reset it again with new time? 回答1

Disable timer within setInterval function with dynamic parameters

拜拜、爱过 提交于 2019-12-08 08:13:00
问题 I wanted to pass dynamic parameters into a setInterval function (see question here) and specifically @tvanfosson's comment. But now, I also want to disable that timer if a certain condition is met. I tried to define the timer variable as a global variable but I still get the timer as a undefined on this line: console.log('else. timer=' + timer); : else. timer=undefined <script language="javascript" type="text/javascript"> var timer; var params={}; params.color='light'; $(document).ready

How can I call clearInterval outside of a function in jQuery? Outside the setInterval

大城市里の小女人 提交于 2019-12-08 07:55:29
问题 function iPadMovie(id) { $(function () { var i = 1; var interval = setInterval(function () { jQuery('.animationMax img').attr({ src: 'http://jdsports.scene7.com/is/image/JDSports/127932jd' + ('0' + i).slice(-2) + '?hei=255&wid=427&resmode=sharp&op_usm=1.1,0.5,0,0&defaultImage=JDSports/sizeImageMissing' }); i++; if (i === 28) i = 1; }, 100); }); } function playIpad(){ iPadMovie(); } function stopIpad(){ clearInterval = interval; } You can see the fiddle here: http://jsfiddle.net/Vv2u3/15/ I

AngularJS notifying view of changes to model

為{幸葍}努か 提交于 2019-12-08 07:50:28
I'm trying to display the current time in a view based on a Javascript Date object in my controller. My controller looks like this: myApp.controller('DateCtrl', function($scope) { var date = new Date(); $scope.minutes = date.getMinutes(); $scope.hours = date.getHours(); $scope.seconds = date.getSeconds(); var updateTime = function() { var date2 = new Date(); $scope.minutes = date2.getMinutes(); $scope.hours = date2.getHours(); $scope.seconds = date2.getSeconds(); } $scope.clickUpdate = function() { setInterval(updateTime, 1000); } }); In my view I simply have: <div ng-controller="DateCtrl">

Javascript loop-problem with setTimeout/setInterval

妖精的绣舞 提交于 2019-12-08 07:17:29
问题 var flag = 0/1 (default=1) I want this flag to checked every 30sec over and over until the flag becomes 0 (by an external event that I cant control). When the flag is 0 the 30sec-check should end until the flag is 1 again As long as the flag is 0 some text should blink on the screen, if the flag goes back to 1 the blinking should stop and the 30sec check should continue. I tried to do this with setTimeout/setInterval but Im having problem combining them with loops. Here is some code doing the

AngularJS notifying view of changes to model

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 06:18:47
问题 I'm trying to display the current time in a view based on a Javascript Date object in my controller. My controller looks like this: myApp.controller('DateCtrl', function($scope) { var date = new Date(); $scope.minutes = date.getMinutes(); $scope.hours = date.getHours(); $scope.seconds = date.getSeconds(); var updateTime = function() { var date2 = new Date(); $scope.minutes = date2.getMinutes(); $scope.hours = date2.getHours(); $scope.seconds = date2.getSeconds(); } $scope.clickUpdate =

How change css using variables to make an animation

半世苍凉 提交于 2019-12-08 04:11:14
问题 How can I transition CSS values using JavaScript? I made this code, but it isn't working: var num = 100; function fillDiv{ var a=document.getElementById("principal"); for (var i = 0; i<100; i++){ num=num-25; a.style.background="-moz-radial-gradient(#FFFFFF "+num+"%, #006699 200%);"; if (num==0){ break; } } In the debug window all gone good, but when I check it on elements tag the value hasn't changed. 回答1: As explained in comments, the for loop is too quick to notice the effect, Instead you