setinterval

用setInterval方法实现弹框闪烁

核能气质少年 提交于 2019-12-05 03:48:57
每次看到某电商平台的拼团提示会觉得很有趣也很方便,正好自己在学习小程序,那就想个法子实现一下这种效果咯~ 思虑了一下还是觉得用setIntercal方法比较简便(数据方面就先不考虑了,我这里只做一下表现效果),基本思路是通过定时来控制拼团提示出现和隐藏;即隔一定时间就将data中传给wx:if里的数据取反(布尔值);写完后我认真的去比对了一下,为什么同样都是闪烁,我的怎么越看越别扭??.... 上图上图[紧张脸] 代码: wxml <view class="invite_container" wx:if="{{show}}"> <navigator class="invitation" animation="{{animationData}}" url="../invitation/invitation"> <view class="invite invite_pic"> <image src="../../images/touxiang.png"></image> </view> <view class="invite invite_content">Lesta邀请您一起剁手</view> </navigator> </view> js //data中,默认拼团提示显示 data: { show: true, } ....... /

Angular 2 call setInterval() undefined Services form Dependency injection

让人想犯罪 __ 提交于 2019-12-04 23:59:32
I want to call a function every 10 minutes by using setInterval() and in this function I want to use a Service (called auth) that I get from the Dependency Injector of Angular 2, the problem is that the console tells me following: EXCEPTION: TypeError: this.auth is undefined constructor(private auth: AuthService){ setInterval(function(){ this.auth.refreshToken(); }, 1000 * 60 * 10); } this in the function given to setInterval doesn't point to the class when it is called. Use arrow function instead. constructor(private auth: AuthService){ setInterval(() => { this.auth.refreshToken(); }, 1000 *

Is there a maximum delay limit for window.setInterval

巧了我就是萌 提交于 2019-12-04 23:36:41
Today I encountered an interesting problem with window.setInterval. When used with a sufficiently large delay (in this case the number of milliseconds in 30 days) it executes every second instead of every 30 days. Tested in latest Chrome and Firefox. jsFiddle link window.setInterval(function() { document.getElementById("first").innerHTML = new Date().toString(); }, 5000); window.setInterval(function() { document.getElementById("second").innerHTML = new Date().toString(); }, 2592000000); I couldn't find any authoritative documentation on the max value of a delay in setInterval, and the MDN

1118 DOM

≡放荡痞女 提交于 2019-12-04 23:01:22
目录 BOM与DOM window对象 navigator对象(了解即可) screen对象(了解即可) history对象(了解即可) location对象 弹出框 计时相关 DOM对象 DOM结构 查找标签 直接查找 间接查找 节点操作 创建节点 添加节点 删除节点: 替换节点: 属性节点 获取值操作 class的操作 指定CSS操作 事件 常用事件 绑定方式 jQuery 介绍 优势 版本 基础语法 使用 jQuery对象 查找标签 基本选择器 层级选择器: 基本筛选器: 属性选择器: 表单筛选器 : BOM与DOM BOM(Browser Object Model)是指浏览器对象模型,它使 JavaScript 有能力与浏览器进行“对话”。 DOM (Document Object Model)是指文档对象模型,通过它,可以访问HTML文档的所有元素。 window对象 Window对象是客户端JavaScript最高层对象之一,由于window对象是其它大部分对象的共同祖先,在调用window对象的方法和属性时,可以省略window对象的引用。例如:window.document.write()可以简写成:document.write()。 window对象方法 方法 说明 open()、close() 打开窗口、关闭窗口 resizeBy()、resizeTo()

BOM和DOM操作

痴心易碎 提交于 2019-12-04 21:24:22
目录 一、父子页面通信 二、window对象 1. window对象的常用方法 (1)window.open() (2)window.close() 2. window 子对象 三、BOM操作 1. BOM 操作常用的方法 (1)navigator 对象 (2)screen 对象 (3)history 对象 (4)location 对象 (5)弹出框 (6)计时相关 四、DOM操作 1. DOM的作用 2. 查找标签 (1)直接查找 (2)间接查找 3. 节点操作 (1)创建节点 (2)添加节点 (3)删除节点 (4)替换节点 (5)属性节点 (6)获取输入input框和选择栏的值 (7)class的操作 (8)指定CSS操作 4. 事件 (1)常用事件 (2)绑定方式 (3)事件的实例 一、父子页面通信 通过 JS 代码实现主页面和弹出的子页面之间的通信 二、window对象 Window对象是客户端JavaScript最高层对象之一,由于window对象是其它大部分对象的共同祖先,在调用window对象的方法和属性时,可以省略window对象的引用。 例如: window.document.write() 可以简写成: document.write() 。 (下面的BOM 和 DOM操作都是省略window后的写法) window对象,大多浏览器都支持window对象

javascript setInterval - countdown lagging [closed]

∥☆過路亽.° 提交于 2019-12-04 18:08:16
I use this code below for a countdown in seconds. The problem is that when the part of the page including the countdown is loaded again using jquery .load, the new countdown becomes wrong : at every second, we see fast 2 seconds, like this : 9-8...7-6...5-4... as if it was not synchronised with the clock... See it there : aorbaroquethrash.com/test (for the problem to happen, I have to change song while you're there) Any idea how I can solve this? <script type = "text/javascript"> /*author Philip M. 2010*/ var timeInSecs; var ticker; function startTimer(secs){ timeInSecs = parseInt(secs)-1;

How to pass intervalID to interval function in javascript?

跟風遠走 提交于 2019-12-04 13:27:50
In javascript when I create an interval, I want to stop the interval from inside the function, but I don't want to reference the ID value from outside like this var y = setInterval(function(){ clearInterval(y); }, 1000); What I want is to pass a variable similar to this style setTimeout(function(data){alert(data);}, 1000, "data"); This works for setInterval too, except I can't really pass the id value that's returned by the setInterval function, because it gets created after calling it. Right now I'm doing a hack like this: var r = []; var y = setInterval(function(r){ if (r.length==1) {

Return value inside a setInterval

萝らか妹 提交于 2019-12-04 12:42:16
I want to return a value inside a setInterval. I just want to execute something with time interval and here's what I've tried: function git(limit) { var i = 0; var git = setInterval(function () { console.log(i); if (i === limit - 1) { clearInterval(git); return 'done'; } i++; }, 800); } var x = git(5); console.log(x); And it's not working. Is there any other way? What I'm going to do with this is to do an animation for specific time interval. Then when i reached the limit (ex. 5x blink by $().fadeOut().fadeIn() ), I want to return a value. This is the application : function func_a(limit) { var

How to trigger a setInterval function on a user click?

蓝咒 提交于 2019-12-04 07:09:51
问题 I'm trying to write a JS timer that will be triggered by a user click on the button with id="start". I've got the timer itself working correctly, but when I try to add code to initiate the timer on the button click (id="start") I break it and am not sure why. Any help would be greatly appreciated! Here is the JS code: $(document).ready(function(){ var count = 0; $('#start').click(function(){ setInterval(function(){ count++; $('#timer').html(count + ' tacos seconds'); },1000); }); }); 回答1: $

setInterval javascript - how to call function

元气小坏坏 提交于 2019-12-04 05:59:05
问题 Here is the simple example of two similar use of setInterval function: http://codepen.io/anon/pen/MwYOOJ In the first example setInterval function does not work, in the second version where below syntax was used it's working fine. /* This part does not work */ var i = 0; function displayNumber() { i++; $('#result').html(i); } setInterval(displayNumber(), 500); /* This part does work */ var j = 0; function displayNumberOk() { j++; $('#result-ok').html(j); } setInterval(function() {