setinterval

Pausing setInterval when page/ browser is out of focus

ぐ巨炮叔叔 提交于 2019-11-30 12:35:24
问题 I have a simple slideshow that I've made on a client's homepage, using setInterval to time the rotations. To prevent browsers from screwing up setInterval when the page isn't in focus (another tab is being viewed, or another programme), I'm using: function onBlur() { clearInterval(play); }; function onFocus() { mySlideRotateFunction(); }; if (/*@cc_on!@*/false) { document.onfocusin = onFocus; document.onfocusout = onBlur; } else { window.onfocus = onFocus; window.onblur = onBlur; } Where

What is the maximum delay for setInterval?

妖精的绣舞 提交于 2019-11-30 08:00:45
问题 I'm having problems on Firefox 15 and Chrome 21 with the following code: setInterval(function () { console.log('test') }, 300000000000) On both browsers, the function is run right away repeats very quickly. Sure, that's a big number (representing about 10 years from now), but I wouldn't expect it to be treated as a tiny or negative number. I haven't seen a maximum allowed delay in any documentation. Does anyone know if there's a standard max, or if this is just the browsers being funny? 回答1:

iOS 6 safari, setInterval doesn't get fired

依然范特西╮ 提交于 2019-11-30 07:30:15
It seems if I'm scrolling the window , the window.setInterval doesn't get attached / fired while the scrolling is happening or after. Has anyone else seen the same issue? I mean... What could be causeing this? What can I do to fix this? jimp iOS halts almost everything in response to user touch to guarantee it feels responsive. The setInterval issue is known, and there doesn't appear to be a workaround. setInterval pauses in iphone/ipad (mobile Safari) during scrolling EDIT During the "freeze" the timer will not catch up once the user releases the screen. The missed events are not deferred,

BOM和DOM

自古美人都是妖i 提交于 2019-11-30 06:55:12
BOM和DOM   BOM(Browser Object Model)是指浏览器对象模型,它使 JavaScript 有能力与浏览器进行“对话”。   DOM (Document Object Model)是指文档对象模型,通过它,可以访问HTML文档的所有元素。 1.BOM 1.window对象 所有浏览器都支持 window 对象。它表示浏览器窗口。   **如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,并为每个框架创建一个额外的 window 对象(了解)。*   **没有应用于 window 对象的公开标准,不过所有浏览器都支持该对象(了解)。*   所有 JavaScript 全局对象、函数以及变量均自动成为 window 对象的成员。   全局变量是 window 对象的属性。全局函数是 window 对象的方法。   接下来要讲的HTML DOM 的 document 也是 window 对象的属性之一。   一些常用的Window方法:(在浏览器调试器的console里面输入下面这些属性或者方法,就能看到对应的效果) window.innerHeight - 浏览器窗口的内部高度 window.innerWidth - 浏览器窗口的内部宽度 window.open() - 打开新窗口 window

how do I pause and resume a timer?

女生的网名这么多〃 提交于 2019-11-30 04:03:19
I got this function that starts a timer on this format 00:00:00 whenever I click on a button. But I don't know how to do functions resume and pause. I've found some snippets that I thought could be helpful but I couldn't make those work. I'm new to using objects in js. function clock() { var pauseObj = new Object(); var totalSeconds = 0; var delay = setInterval(setTime, 1000); function setTime() { var ctr; $(".icon-play").each(function () { if ($(this).parent().hasClass('hide')) ctr = ($(this).attr('id')).split('_'); }); ++totalSeconds; $("#hour_" + ctr[1]).text(pad(Math.floor(totalSeconds /

Web前端——JavaScript练习

岁酱吖の 提交于 2019-11-30 03:12:42
Js练习 显示和隐藏,改变display属性(点击查看图片) 关键代码: 复制e.style.display = "block"; e.style.display = "none"; 源码: 复制<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>显示和隐藏</title> <script type="text/javascript"> function showPicture(){ //普通方式获得控件实例 var e = document.getElementById("myimg"); e.style.display = "block"; } function hidePicture(){ //querySelector是html5增加的 //id前面得写#,class前面得写 document.querySelector("#myimg").style.display = "none"; //标签直接写即可,获取到第一个img标签 //document.querySelector("img").style.display = "none"; } </script> </head> <body> <a href="javascript:void(0);"onclick="showPicture()">查看图片

Pausing setInterval when page/ browser is out of focus

末鹿安然 提交于 2019-11-30 03:08:05
I have a simple slideshow that I've made on a client's homepage, using setInterval to time the rotations. To prevent browsers from screwing up setInterval when the page isn't in focus (another tab is being viewed, or another programme), I'm using: function onBlur() { clearInterval(play); }; function onFocus() { mySlideRotateFunction(); }; if (/*@cc_on!@*/false) { document.onfocusin = onFocus; document.onfocusout = onBlur; } else { window.onfocus = onFocus; window.onblur = onBlur; } Where mySlideRotateFunction sets the setInterval and runs some jQuery. While this works the majority of the time,

JS day2 BOM DOM jq day1 # 48

烂漫一生 提交于 2019-11-30 01:19:58
day48 JS day2 BOM DOM jq day1 1.前端 与浏览器交互 1.BOM操作 1.BOM介绍 1 BOM操作: 2 (Browser Object Model) 3 是指浏览器对象模型, 4 它使 JavaScript 有能力与浏览器进行“对话”。 5 6 弹出窗口 1.BOM介绍 2.一些常用的window方法 1 Window对象 2 是客户端JavaScript最高层对象之一, 3 由于window对象是其它大部分对象的共同祖先, 4 在调用window对象的方法和属性时, 5 可以省略window对象的引用。 6 例如: 7 //document文件 8 window.document.write() 9 简写为: 10 document.write() 11 12 13 接下来要讲的HTML DOM 的 document 也是 window 对象的属性之一。 14 15 所有的对象都支持window对象 他表示浏览器窗口. 16 17 一些常用的Window方法: 18 window.innerHeight 浏览器窗口的内部高度 19 window.innerWidth 浏览器窗口的内部宽度 20 window.open() 打开新窗口 21 window.close() 关闭当前窗口 2.一些常用的window方法 3.window 子对象 1

51 前端--BOM/DOM

ぐ巨炮叔叔 提交于 2019-11-29 22:17:03
目录 BOM 1. window对象 window的子对象 navigator对象 screen对象 history对象 location对象(***) 2. 弹出框 警告框 确认框 提示框 3. 计时器(***) setTimeout :一段时间后做一些事情 clearTimeout():取消setTimeout设置 setInterval(): 每隔一段时间做一些事情 clearInterval():取消setInterval设置 DOM 1. HTML DOM 树 2. 查找标签 3. 间接查找 4. 节点操作 创建节点:(创建标签) 添加节点 删除节点: 替换节点: 属性节点: 获取值操作: class的操作 css设置操作 事件 BOM BOM(Browser Object Model)是指浏览器对象模型,它使 JavaScript 有能力与浏览器进行“对话”。 1. window对象 window.innerHeight - 浏览器窗口的内部高度 window.innerWidth - 浏览器窗口的内部宽度 window.open() - 打开新窗口 window.close() - 关闭当前窗口 (只能关闭用js的打开的页面) window的子对象 navigator对象 navigator.appName  // Web浏览器全称 "Netscape"

Javascript setInterval function to clear itself?

荒凉一梦 提交于 2019-11-29 22:04:50
myInterval = setInterval(function(){ MyFunction(); },50); function MyFunction() { //Can I call clearInterval(myInterval); in here? } The interval's not stopping (not being cleared), if what I've coded above is fine then it'll help me look elsewhere for what's causing the problem. Thanks. EDIT: Let's assume it completes a few intervals before clearInterval is called which removes the need for setTimeout. As long as you have scope to the saved interval variable, you can cancel it from anywhere. In an "child" scope: var myInterval = setInterval(function(){ clearInterval(myInterval); },50); In a