settimeout

前端之Bom和Dom

点点圈 提交于 2019-12-28 04:41:47
前端基础之Bom和Dom 简介: Bom(Browser Object Model)是指浏览器对象模型,它使JavaScript有能力与浏览器进行'对话' Dom(Document Object Model)是指文档对象模型,通过它,可以访问HTML文档的所有元素 Window对象是客户端JavaScript最高层对象之一,由于window对象是其他大部分对象的共同祖先,在调用window对象的方法和属性时,可以省略window对象的引用,例如:window.document.write()可以简写成document.write() 1.window对象 所有浏览器都支持window对象,它表示浏览器窗口 如果文档包含框架(frame或ifram标签),浏览器会为HTML文档创建一个window对象,并为每个框架创建一个额外的window对象 没有应用于window对象的公开标准,不过所有浏览器都支持该对象 所有JavaScript全局对象、函数以及变量均自动成为window对象的成员 全局变量是window对象的属性,全局函数是window对象的方法 接下来的HTML Dom的document也是window对象的属性之一 一些常用的window方法: window.innerHeight:浏览器窗口的内部高度 window.innerWidth:浏览器窗口的内部宽度

前端js之BOM和DOM

家住魔仙堡 提交于 2019-12-28 04:41:37
BOM与DOM   BOM(Browser Object Model)是指浏览器对象模型,它使 JavaScript 有能力与浏览器进行“对话”。   DOM (Document Object Model)是指文档对象模型,通过它,可以访问HTML文档的所有元素。   Window对象是客户端JavaScript最高层对象之一,由于window对象是其它大部分对象的共同祖先,在调用window对象的方法和属性时,可以省略window对象的引用。例如:window.document.write()可以简写成:document.write()。 windows对象 所有浏览器都支持 window 对象。它表示浏览器窗口。 *如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,并为每个框架创建一个额外的 window 对象。 *没有应用于 window 对象的公开标准,不过所有浏览器都支持该对象。 所有 JavaScript 全局对象、函数以及变量均自动成为 window 对象的成员。 全局变量是 window 对象的属性。全局函数是 window 对象的方法。 接下来要讲的HTML DOM 的 document 也是 window 对象的属性之一。 一些常用的Window方法: window.innerHeight -

Are equal timeouts executed in order in Javascript?

核能气质少年 提交于 2019-12-28 02:52:09
问题 Suppose I do setTimeout(foo, 0); ... setTimeout(bar, 0); Can I be sure foo will begin executing before bar? What if instead of 0 I use a timeout of 1, 10, or 100 for bar? Simple experiments show that in the case of equal timeout values the timeout targets are executed in the same order as the setTimeouts themselves, but is it safe to rely on this behavior? 回答1: It is not safe to rely on this behavior. I wrote a test script which schedules a number of functions (and they in turn also schedule

What happens to setTimeout when the computer goes to sleep?

心已入冬 提交于 2019-12-28 01:52:52
问题 In a modern web browser, suppose I do a setTimeout for 10 minutes (at 12:00), and 5 minutes later put the computer to sleep, what should happen when the system wakes up again? What happens if it wakes up before the 10 minutes are up (at 12:09) or much later (at 16:00)? The reason I'm asking is because I'd like to have a new authentication token requested every 10 minutes, and I'm not sure if the browser will do the right thing and immediately request a new token if it wakes up after a long

How to stop a setTimeout loop?

十年热恋 提交于 2019-12-27 11:50:58
问题 I'm trying to build a loading indicator with a image sprite and I came up with this function function setBgPosition() { var c = 0; var numbers = [0, -120, -240, -360, -480, -600, -720]; function run() { Ext.get('common-spinner').setStyle('background-position', numbers[c++] + 'px 0px'); if (c<numbers.length) { setTimeout(run, 200); }else { setBgPosition(); } } setTimeout(run, 200); } so the out put is looks like this http://jsfiddle.net/TTkre/ I had to use setBgPosition(); inside else to keep

setTimeout() is not waiting

风格不统一 提交于 2019-12-27 11:49:33
问题 I am trying to make a seconds countdown with Javascript. Here is my HTML <div id="ban_container" class="error center">Please wait <span id="ban_countdown" style="font-weight:bold"> 45</span> seconds before trying again </div> And my JS: <script type="text/javascript"> var seconds = <?php echo $user->getBlockExpiryRemaining(); ?>; function countdown(element) { var el = document.getElementById(element); if (seconds === 0) { document.getElementById("ban_container").innerHTML = "done"; return; }

How to stop a setTimeout loop?

北城余情 提交于 2019-12-27 11:47:40
问题 I'm trying to build a loading indicator with a image sprite and I came up with this function function setBgPosition() { var c = 0; var numbers = [0, -120, -240, -360, -480, -600, -720]; function run() { Ext.get('common-spinner').setStyle('background-position', numbers[c++] + 'px 0px'); if (c<numbers.length) { setTimeout(run, 200); }else { setBgPosition(); } } setTimeout(run, 200); } so the out put is looks like this http://jsfiddle.net/TTkre/ I had to use setBgPosition(); inside else to keep

setTimeout() is not waiting

时光怂恿深爱的人放手 提交于 2019-12-27 11:47:12
问题 I am trying to make a seconds countdown with Javascript. Here is my HTML <div id="ban_container" class="error center">Please wait <span id="ban_countdown" style="font-weight:bold"> 45</span> seconds before trying again </div> And my JS: <script type="text/javascript"> var seconds = <?php echo $user->getBlockExpiryRemaining(); ?>; function countdown(element) { var el = document.getElementById(element); if (seconds === 0) { document.getElementById("ban_container").innerHTML = "done"; return; }

How do I get my image slider to reset its auto-scroll timer after a click?

て烟熏妆下的殇ゞ 提交于 2019-12-25 07:07:13
问题 I have an image slider with n amount of images. It scrolls automatically between each one every 5 seconds. There is a "previous" and "next" button on either side of the slider. $('#button-next').click(function () { //goes to next slide }); $('#button-prev').click(function () { //goes to previous slide }); var _scrollInterval = AutoScroll(); function AutoScroll() { var temp = setInterval(function () { $('#button-next').click(); }, 5000) return temp; } My desired functionality is that when the

Dojo: using setTimeout to load widgets in async way

独自空忆成欢 提交于 2019-12-25 03:53:09
问题 Imagine that we have a Sequence widget which loads Element widgets and loads some config for each of them (through loadConfig() ) .Schematic view is described on the image below: The problem is that every approach I tried does the same "bad" thing: it freezes everything until all Elements are loaded. array.forEach(elements, function(element) { element.loadConfig(); }); or var counter = 0; var loadConfig = function(element) { element.loadConfig() if (++counter <= elements.length - 1) {