å
容
ããªãã¯ããªãã®å¿ã«åãæã£ãŠããŸãããå€éšã®åºæ¥äºã«ã¯åããããŸããã ãããçè§£ãããšãããªãã¯åãåŸãŸãã
ããŒã«ã¹ã¢ãŠã¬ãªãŠã¹ãçæ³ãäžéšã®ããã°ã©ã ã¯ããŠãŒã¶ãŒå
¥åãããŠã¹ãããã³ããŒããŒãã§åäœããŸãã ãã®ãããªå
¥åã®çºçæå»ãšããŒã¿ã®ã·ãŒã±ã³ã¹ã¯ãäºåã«äºæž¬ããããšã¯ã§ããŸããã ããã«ã¯ãããã°ã©ã ã®å®è¡é åºãå¶åŸ¡ããããã«ããã§ã«ããç¥ãããŠãããã®ãšã¯ç°ãªãã¢ãããŒããå¿
èŠã§ãã
ã€ãã³ããã³ãã©ãŒ
ããŒããŒãã®ãã¿ã³ãæŒããããã©ããã確èªããå¯äžã®æ¹æ³ãããã¿ã³ã®çŸåšã®ç¶æ
ãèªã¿åãããšã§ããã€ã³ã¿ãŒãã§ãŒã¹ãæ³åããŠãã ããã ã¯ãªãã¯ã«å¿çããã«ã¯ããã¿ã³ã®ç¶æ
ãåžžã«èªã¿åã£ãŠããã¿ã³ãæŸããããŸã§ãã®ç¶æ
ããã£ããã§ããããã«ããå¿
èŠããããŸãã æŒãç¬éãã¹ãããã§ãããããããã»ããµæéãæ¶è²»ããä»ã®èšç®ãè¡ãããšã¯å±éºã§ãã
ãããã£ãŠãå
¥åã¯ããªããã£ãããã€ã¹ã§åŠçãããŸããã ããŒããŠã§ã¢ãŸãã¯OSããã¿ã³ãæŒãããããšãèªèããããããã¥ãŒã«è»¢éããå Žåãåé²ããŸãã ãã®åŸãããã°ã©ã ã¯å®æçã«æ°ããã€ãã³ãã®ãã¥ãŒããã§ãã¯ãããã¥ãŒã«ãããã®ã«å¿çã§ããŸãã
ãã¡ããããã¿ã³ãæŒããŠããããã°ã©ã ãããã«æ°ä»ããŠåå¿ãããŸã§ã®æéãé·ããšããã®ããã°ã©ã ããã£ããå®è¡ãããŠãããšèªèãããããã圌女ã¯ãã§ãã¯ããããšãå¿ããªãã§ãã ããã ãã®ã¢ãããŒãã¯ãã£ãã«äœ¿çšãããŸããã
ããè¯ããªãã·ã§ã³ã¯ãã€ãã³ããçºçãããšãã«ã³ãŒããã€ãã³ãã«å¿çã§ããããã«ããäžçš®ã®äžéã·ã¹ãã ã§ãã ãã©ãŠã¶ãŒã§ã¯ãç¹å®ã®ã€ãã³ãã®ãã³ãã©ãŒãšããŠé¢æ°ãç»é²ããããšã«ããããããè¡ãããšãã§ããŸãã
<p> .</p> <script> addEventListener("click", function() { console.log("!"); }); </script>
addEventListener颿°ã¯ã2çªç®ã®åŒæ°ããæåã®åŒæ°ã§èª¬æãããŠããã€ãã³ããçºçãããšãã«åŒã³åºããã颿°ãšããŠç»é²ããŸãã
ã€ãã³ããšDOMããŒã
åãã©ãŠã¶ãŒã€ãã³ããã³ãã©ãŒã¯ã³ã³ããã¹ãã§ç»é²ãããŸãã ãã©ãŠã¶ã§ã¯ã°ããŒãã«ã¹ã³ãŒãããŠã£ã³ããŠãªããžã§ã¯ãã§ãããããaddEventListenerãåŒã³åºããšãã¯ããŠã£ã³ããŠå
šäœã®ã¡ãœãããšããŠåŒã³åºããŸãã åDOMèŠçŽ ã«ã¯ç¬èªã®addEventListenerã¡ãœãããããããã®èŠçŽ ããã€ãã³ãããªãã¹ã³ã§ããŸãã
<button> .</button> <p> .</p> <script> var button = document.querySelector("button"); button.addEventListener("click", function() { console.log(" ."); }); </script>
ãã®äŸã§ã¯ããã¿ã³ã®DOMããŒãã«ãã³ãã©ãŒãå²ãåœãŠãŸãã ãã¿ã³ãæŒããšãã³ãã©ãŒãèµ·åããããã¥ã¡ã³ãã®ä»ã®éšåãã¯ãªãã¯ããŠãèµ·åããŸããã
onclick屿§ãããŒãã«å²ãåœãŠãããšãåæ§ã«æ©èœããŸãã ãã ããããŒãã«ã¯onclick屿§ã1ã€ãããããŸãããã€ãŸãããã®æ¹æ³ã§ã¯1ã€ã®ãã³ãã©ãŒããç»é²ã§ããŸããã addEventListenerã¡ãœããã䜿çšãããšãä»»æã®æ°ã®ãã³ãã©ãŒã远å ã§ããããã以åã«ã©ã³ãã ã«å²ãåœãŠããããã³ãã©ãŒã眮ãæããããšã¯ãããŸããã
addEventListenerãšåãåŒæ°ã§åŒã³åºãããremoveEventListenerã¡ãœããã¯ããã³ãã©ãŒãåé€ããŸãã
<button>Act-once button</button> <script> var button = document.querySelector("button"); function once() { console.log("Done."); button.removeEventListener("click", once); } button.addEventListener("click", once); </script>
ãããè¡ãã«ã¯ã颿°ã«ååãä»ãïŒãã®å Žåã¯1åïŒãaddEventListenerãšremoveEventListenerã®äž¡æ¹ã«æž¡ãããšãã§ããããã«ããŸãã
ã€ãã³ããªããžã§ã¯ã
äŸã§ã¯ãåŒæ°ããã³ãã©ãŒé¢æ°ïŒã€ãã³ããªããžã§ã¯ãïŒã«æž¡ããããšããäºå®ãç¡èŠããŸããã ã€ãã³ãã«é¢ããè¿œå æ
å ±ãä¿åããŸãã ããšãã°ãã¯ãªãã¯ãããããŠã¹ãã¿ã³ãç¥ãå¿
èŠãããå Žåããã®ãªããžã§ã¯ãã®ã©ã®ããããã£ãåç
§ã§ããŸãã
<button> , !</button> <script> var button = document.querySelector("button"); button.addEventListener("mousedown", function(event) { if (event.which == 1) console.log(""); else if (event.which == 2) console.log(""); else if (event.which == 3) console.log(""); }); </script>
ãªããžã§ã¯ãã«ä¿åãããæ
å ±ã¯ãã€ãã³ãã®çš®é¡ããšã«ç°ãªããŸãã ãããã®ã¿ã€ãã«ã€ããŠã¯åŸã§èª¬æããŸãã ã¿ã€ããªããžã§ã¯ãã®ããããã£ã«ã¯ãåžžã«ã€ãã³ãã説æããæååãå«ãŸããŸãïŒããšãã°ããã¯ãªãã¯ããŸãã¯ãããŠã¹ãïŒã
äŒæ
åããŒããæã€ããŒãã«ç»é²ãããã€ãã³ãã¯ãåã«çºçããã€ãã³ããåãåããŸãã æ®µèœå
ã®ãã¿ã³ãã¯ãªãã¯ãããšã段èœã®ã€ãã³ããã³ãã©ãŒãã¯ãªãã¯ã€ãã³ããåãåããŸãã
段èœãšãã¿ã³ã®äž¡æ¹ã«ãã³ãã©ãŒãããå Žåãããå
·äœçãªãã®ãæåã«èµ·åããŸããã€ãŸãããã¿ã³ãã³ãã©ãŒã§ãã ã€ãã³ãã¯ããããçºçããããŒããããã®èŠªãããã«ããã¥ã¡ã³ãã®ã«ãŒããŸã§å€åŽã«åºãããŸãã ãã¹ãŠã®äžéããŒãã®ãã¹ãŠã®ãã³ãã©ãŒãåŠçããåŸãã€ãã³ãã«å¿çãããã¥ãŒã¯ãŠã£ã³ããŠèªäœã«å°éããŸãã
ãã³ãã©ã¯ãã€ã§ããã€ãã³ããªããžã§ã¯ãã®stopPropagationã¡ãœãããåŒã³åºããŠããäžäœãããŒãããããåãåããªãããã«ããããšãã§ããŸãã ããã¯ãå¥ã®ã¯ãªãã¯å¯èœãªèŠçŽ å
ã«ãã¿ã³ãããããã¿ã³ãã¯ãªãã¯ããŠå€éšèŠçŽ ã®åäœãã¢ã¯ãã£ãã«ããããªãå Žåã«åœ¹ç«ã¡ãŸãã
次ã®äŸã§ã¯ããã¿ã³ãšåšå²ã®æ®µèœã®äž¡æ¹ã«ãmousedownããã³ãã©ãŒãç»é²ããŸãã å³ã¯ãªãã¯ãããšããã¿ã³ãã³ãã©ãŒã¯stopPropagationãåŒã³åºããæ®µèœãã³ãã©ãŒãéå§ãããªãããã«ããŸãã å¥ã®ãã¿ã³ãã¯ãªãã¯ãããšãäž¡æ¹ã®ãã³ãã©ãŒãèµ·åããŸãã
<p> <button> </button>.</p> <script> var para = document.querySelector("p"); var button = document.querySelector("button"); para.addEventListener("mousedown", function() { console.log(" ."); }); button.addEventListener("mousedown", function(event) { console.log(" ."); if (event.which == 3) event.stopPropagation(); }); </script>
ã»ãšãã©ã®ã€ãã³ããªããžã§ã¯ãã«ã¯ãåŠçãéå§ããããŒããåç
§ããã¿ãŒã²ããããããã£ããããŸãã äžèŠãªããŒãããã®äœããåŠçããŠããªãããšã確èªããããã«äœ¿çšã§ããŸãã
ã¿ãŒã²ããããããã£ã䜿çšããŠãç¹å®ã®çš®é¡ã®ã€ãã³ãã®åŠçãæ¡åŒµããããšãã§ããŸãã ããšãã°ããã¿ã³ã®é·ããªã¹ããå«ãããŒããããå ŽåãããŒãã®ã€ãã³ããã³ãã©ãŒã1ã€ç»é²ããåãã¿ã³ã®ãã³ãã©ãŒãåå¥ã«ç»é²ããã®ã§ã¯ãªãããã¿ã³ãã¯ãªãã¯ããããã©ããã調ã¹ãæ¹ã䟿å©ã§ãã
<button>A</button> <button>B</button> <button>C</button> <script> document.body.addEventListener("click", function(event) { if (event.target.nodeName == "BUTTON") console.log("Clicked", event.target.textContent); }); </script>
ããã©ã«ãã®ã¢ã¯ã·ã§ã³
å€ãã®ã€ãã³ãã«ã¯ããã©ã«ãã®ã¢ã¯ã·ã§ã³ããããŸãã ãªã³ã¯ãã¯ãªãã¯ãããšããªã³ã¯ããã©ããŸãã äžç¢å°ãã¯ãªãã¯ãããšããã©ãŠã¶ã¯ããŒãžãäžã«ã¹ã¯ããŒã«ããŸãã å³ã¯ãªãã¯ãããšãã³ã³ããã¹ãã¡ãã¥ãŒã衚瀺ãããŸãã ãªã©ãªã©ã
ã»ãšãã©ã®ã¿ã€ãã®ã€ãã³ãã§ã¯ãããã©ã«ãã¢ã¯ã·ã§ã³ãèµ·åããåã«ã€ãã³ããã³ãã©ãŒãåŒã³åºãããŸãã ãã³ãã©ãŒããã®ã¢ã¯ã·ã§ã³ãçºçãããããªãå ŽåïŒå€ãã®å Žåãæ¢ã«ã¢ã¯ã·ã§ã³ãåŠçããŠããããïŒãã€ãã³ããªããžã§ã¯ãã®preventDefaultã¡ãœãããåŒã³åºãããšãã§ããŸãã
ããã䜿çšããŠãç¬èªã®ããŒããŒãã·ã§ãŒãã«ãããŸãã¯ã³ã³ããã¹ãã¡ãã¥ãŒãäœæã§ããŸãã ãŸãã䜿ãæ
£ãããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãå£ãããã«ã䜿çšã§ããŸãã ããšãã°ãããã«ããªãããã©ãããšãã§ããªããªã³ã¯ããããŸãã
<a href="https://developer.mozilla.org/">MDN</a> <script> var link = document.querySelector("a"); link.addEventListener("click", function(event) { console.log("."); event.preventDefault(); }); </script>
ãããããªãã§ãã ãã-éåžžã«æ·±å»ãªçç±ããªãéãïŒ ããŒãžã®ãŠãŒã¶ãŒã¯ãã¢ã¯ã·ã§ã³ã®äºæããªãçµæã«ééãããšéåžžã«äžå¿«ã«ãªããŸãã ãã©ãŠã¶ã«ãã£ãŠã¯ãäžéšã®ã€ãã³ããã€ã³ã¿ãŒã»ããã§ããŸããã Chromeã§ã¯ãçŸåšã®ããã¯ããŒã¯ãéããããã®ãããããŒïŒCtrl-WãŸãã¯Command-WïŒãåŠçã§ããŸããã
ããŒããŒããã¿ã³ããã®ã€ãã³ã
ããŒããŒãã®ãã¿ã³ãæŒããããšããã©ãŠã¶ãŒã¯keydownã€ãã³ããçºçãããŸãã ãªãªãŒã¹ããããšãããŒã¢ããã€ãã³ããçºçããŸãã
<p> V .</p> <script> addEventListener("keydown", function(event) { if (event.keyCode == 86) document.body.style.background = "violet"; }); addEventListener("keyup", function(event) { if (event.keyCode == 86) document.body.style.background = ""; }); </script>
ååã«ããããããããããŒããŠã³ãã¯ãã¿ã³ãæŒããããšãã ãã§ãªãçºçããŸãã ãã¿ã³ãæŒãããŸãŸã«ãããšãããŒããã®2çªç®ã®ä¿¡å·ãå°çãããã³ã«ã€ãã³ããçºçããŸãïŒããŒãªããŒãïŒã ããšãã°ãç¢å°ä»ãã®ãã¿ã³ãæŒãããšãã«ã²ãŒã ãã£ã©ã¯ã¿ãŒã®é床ãäžãããã¿ã³ãæŸãããšãã«é床ãäžããå¿
èŠãããå Žåããã¿ã³ããã®ä¿¡å·ãç¹°ãè¿ããã³ã«é床ãäžããªãããã«æ³šæããå¿
èŠããããŸããããããªããšãé床ãéåžžã«éããªããŸãã
ãã®äŸã§ã¯ãã€ãã³ããªããžã§ã¯ãã®keyCodeããããã£ã«èšåããŠããŸãã ãããã£ãŠãã©ã®ãã¿ã³ãæŒãããããé¢ããããã調ã¹ãããšãã§ããŸãã æ®å¿µãªãããæ°å€ã³ãŒããç®çã®ãã¿ã³ã«å€æããæ¹æ³ã¯å¿
ãããæããã§ã¯ãããŸããã
æ°åãšæåã®å Žåãã³ãŒãã¯ãã¿ã³ã«è¡šç€ºããã倧æåã«é¢é£ä»ããããUnicodeæåã³ãŒãã«ãªããŸãã æååã¡ãœããcharCodeAtã¯ãã®ã³ãŒããæäŸããŸãã
console.log("Violet".charCodeAt(0));
ä»ã®ãã¿ã³ã«ã¯äºæž¬äžå¯èœãªã³ãŒãããããŸãã ããããèŠã€ããæè¯ã®æ¹æ³ã¯å®éšçã§ãã ããŒã³ãŒããæžã蟌ããã³ãã©ãŒãç»é²ããç®çã®ãã¿ã³ãæŒããŸãã
ShiftãCtrlãAltãMetaïŒMacã®ã³ãã³ãïŒãªã©ã®ä¿®é£Ÿãã¿ã³ã¯ãéåžžã®ãã¿ã³ãšåæ§ã«ã€ãã³ããäœæããŸãã ãã ããããŒããŒãã·ã§ãŒãã«ãããè§£æããå ŽåãããŒããŒãã€ãã³ãããã³ããŠã¹ã€ãã³ãã®shiftKeyãctrlKeyãaltKeyãããã³metaKeyããããã£ãä»ããŠä¿®é£ŸåãæŒããããã©ããã確èªã§ããŸãã
<p> Ctrl-Space .</p> <script> addEventListener("keydown", function(event) { if (event.keyCode == 32 && event.ctrlKey) console.log("!"); }); </script>
ãããŒããŠã³ãããã³ãããŒã¢ãããã€ãã³ãã¯ããã¿ã³ãç©ççã«æŒãããšã«é¢ããæ
å ±ãæäŸããŸãã ãŸãããŠãŒã¶ãŒãå
¥åããããã¹ããç¥ãå¿
èŠãããå Žåã¯ã©ããªããŸããïŒ ãã¿ã³ãæŒããŠäœæããã®ã¯äžäŸ¿ã§ãã ãããè¡ãããã«ããkeydownãã®çŽåŸã«çºçãããkeypressãã€ãã³ãããããŸãïŒããŒããŸã ä¿æãããŠããå Žåã¯ãkeydownããšãšãã«ç¹°ãè¿ãããŸãïŒããæåãçºè¡ãããã¿ã³ã®ã¿ã§ãã charCodeã€ãã³ããªããžã§ã¯ãããããã£ã«ã¯ãUnicodeã³ãŒããšããŠè§£éã§ããã³ãŒããå«ãŸããŠããŸãã String.fromCharCode颿°ã䜿çšããŠãã³ãŒããåäžã®æååã«å€æã§ããŸãã
<p> .</p> <script> addEventListener("keypress", function(event) { console.log(String.fromCharCode(event.charCode)); }); </script>
ããŒãã¯ãããŒã¹ãããŒã¯äžã«å
¥åãã©ãŒã«ã¹ããã£ãå Žæã«å¿ããŠãããŒã¹ãããŒã¯ã€ãã³ãã®ãœãŒã¹ã«ãªããŸãã éåžžã®ããŒãã¯ïŒtabindex屿§ãèšå®ããªãéãïŒå
¥åãã©ãŒã«ã¹ãååŸã§ããŸãããããªã³ã¯ããã¿ã³ããã©ãŒã ãã£ãŒã«ããªã©ã¯ååŸã§ããŸãã 第18ç« ã®å
¥åãã£ãŒã«ãã«æ»ããŸãããã©ãŒã«ã¹ããªãå Žåãdocument.bodyã¯ã¿ãŒã²ããã€ãã³ãããŒããšããŠæ©èœããŸãã
ããŠã¹ãã¿ã³
ããŠã¹ãã¯ãªãã¯ãããšãããã€ãã®ã€ãã³ããããªã¬ãŒãããŸãã mousedownã€ãã³ããšmouseupã€ãã³ãã¯keydownã€ãã³ããškeyupã€ãã³ãã«äŒŒãŠããããã¿ã³ãæŒããããšããšé¢ããããšãã«çºçããŸãã ã€ãã³ãã¯ãããŠã¹ã«ãŒãœã«ã眮ãããDOMããŒãã§çºçããŸãã
ãããŠã¹ã¢ãããã€ãã³ãã®åŸããããããŠãªãªãŒã¹ãããããŒãã§ãã¯ãªãã¯ãã€ãã³ããããªã¬ãŒãããŸãã ããšãã°ãããæ®µèœäžã®ãã¿ã³ãã¯ãªãã¯ããŠãããããŠã¹ãå¥ã®æ®µèœã«ç§»åããŠãã¿ã³ãé¢ããšããããã®äž¡æ¹ã®æ®µèœãå«ãèŠçŽ ã§ãã¯ãªãã¯ãã€ãã³ããçºçããŸãã
2åã®ã¯ãªãã¯ã次ã
ãšçºçããå Žåã2åç®ã®ãã¯ãªãã¯ãã®å®è¡çŽåŸã«ãdblclickãïŒããã«ã¯ãªãã¯ïŒã€ãã³ããçºçããŸãã
ããŠã¹ã€ãã³ããçºçããå Žæã®æ£ç¢ºãªåº§æšãååŸããã«ã¯ãpageXããããã£ãšpageYããããã£ãåç
§ããŸãããããã®ããããã£ã«ã¯ãå·Šäžé
ãåºæºãšãããã¯ã»ã«åäœã®åº§æšãå«ãŸããŸãã
ãã®äŸã§ã¯ãããªããã£ããªæç»ããã°ã©ã ãäœæãããŸãã ããã¥ã¡ã³ããã¯ãªãã¯ãããã³ã«ãã«ãŒãœã«ã®äžã«ãã€ã³ãã远å ãããŸãã 第19ç« ã§ã¯ãããŸãåå§çã§ãªãæç»ããã°ã©ã ã玹ä»ããŸãã
<style> body { height: 200px; background: beige; } .dot { height: 8px; width: 8px; border-radius: 4px; background: blue; position: absolute; } </style> <script> addEventListener("click", function(event) { var dot = document.createElement("div"); dot.className = "dot"; dot.style.left = (event.pageX - 4) + "px"; dot.style.top = (event.pageY - 4) + "px"; document.body.appendChild(dot); }); </script>
clientXããã³clientYããããã£ã¯pageXããã³pageYã«äŒŒãŠããŸãããçŸåšè¡šç€ºãããŠããããã¥ã¡ã³ãã®éšåã«çžå¯Ÿçãªåº§æšãæäŸããŸãïŒããã¥ã¡ã³ããã¹ã¯ããŒã«ãããŠããå ŽåïŒã ããã¯ãããŠã¹ã®åº§æšãgetBoundingClientRectãè¿ã座æšãšæ¯èŒãããšãã«äŸ¿å©ã§ãããã®æ»ãå€ã¯ãããã¥ã¡ã³ãã®è¡šç€ºéšåã®çžå¯Ÿåº§æšã«ãé¢é£ããŠããŸãã
ããŠã¹ã®åã
ããŠã¹ã«ãŒãœã«ãç§»åãããã³ã«ãmousemoveã€ãã³ããçºçããŸãã ããŠã¹ã®äœçœ®ã远跡ããããã«äœ¿çšã§ããŸãã éåžžãããã¯ããŠã¹ã§ãªããžã§ã¯ãããã©ãã°ããããšã«é¢é£ããæ©èœãäœæãããšãã«å¿
èŠã§ãã
ããšãã°ã次ã®ããã°ã©ã ã¯ããŒã衚瀺ããå·Šå³ã«ç§»åãããšå¹
ã墿žããããã«ã€ãã³ãåŠçãèšå®ããŸãã
<p> :</p> <div style="background: orange; width: 60px; height: 20px"> </div> <script> var lastX;
ãmousemoveããã³ãã©ãŒã¯ãŠã£ã³ããŠå
šäœã«ç»é²ãããããšã«æ³šæããŠãã ããã ããŠã¹ãã¹ããªãããè¶
ããå Žåã§ãããã¿ã³ãæŸãããšãã«ãµã€ãºãæŽæ°ããŠåæ¢ããå¿
èŠããããŸãã
ã«ãŒãœã«ãããŒãã«åºå
¥ããããšããããŠã¹ãªãŒããŒããŸãã¯ãããŠã¹ã¢ãŠããã€ãã³ããçºçããŸãã ç¹ã«ãã«ãŒãœã«ããã®èŠçŽ ã®äžã«çœ®ãããšãã«ããŠã¹ãä¿æããããäœãã®ã¹ã¿ã€ã«ã衚瀺ãŸãã¯å€æŽããããã广ãäœæããããã«äœ¿çšã§ããŸãã
æ®å¿µãªããããã®ãããªå¹æã®äœæã¯ãmouseoverã€ãã³ãã§ããªã¬ãŒããmouseoutã€ãã³ãã§çµäºããããšã«éå®ãããŸããã ããŠã¹ãããŒããããã®åããŒãã«ç§»åãããšãäžè¬çã«èšãã°ãããŠã¹ã¯ãããé¢ããŸããã§ããããããŠã¹ã¢ãŠãã€ãã³ãã芪ããŒãã§çºçããŸãã ããã«æªãããšã«ããããã®ã€ãã³ãã¯ä»ã®ãã¹ãŠã®ã€ãã³ããšåãããã«äŒæããããããã³ãã©ãŒãç»é²ããããŒãã®åã®1ã€ããã«ãŒãœã«ãé¢ãããšããããŠã¹ã¢ãŠãããçºçããŸãã
ãã®åé¡ãåé¿ããã«ã¯ãã€ãã³ããªããžã§ã¯ãã®relatedTargetããããã£ã䜿çšããŸãã mouseoverã€ãã³ããçºçãããšãã«ããŠã¹ãã©ã®ããŒãã®åã«ãã£ãããmouseoutã€ãã³ããçºçãããšãã«ã©ã®èŠçŽ ã«ãžã£ã³ããããã瀺ããŸãã relatedTargetãã¿ãŒã²ããããŒãã®å€åŽã«ããå Žåã«ã®ã¿ããšãã§ã¯ãã倿Žããå¿
èŠããããŸãã ãã®å Žåã«ã®ã¿ãã€ãã³ãã¯å®éã«ããŒããžã®é·ç§»ïŒãŸãã¯ããŒãããã®é¢è±ïŒã衚ããŸãã
<p> <strong> </strong>.</p> <script> var para = document.querySelector("p"); function isInside(node, target) { for (; node != null; node = node.parentNode) if (node == target) return true; } para.addEventListener("mouseover", function(event) { if (!isInside(event.relatedTarget, para)) para.style.color = "red"; }); para.addEventListener("mouseout", function(event) { if (!isInside(event.relatedTarget, para)) para.style.color = ""; }); </script>
isInside颿°ã¯ãããã¥ã¡ã³ãã®æäžéšã«å°éãããŸã§ïŒãããŠããŒããnullã«ãªããŸã§ïŒããŒãã®ãã¹ãŠã®ç¥å
ãå埩ããããæå®ããã芪ãèŠã€ããããŸããã
以äžã«ç€ºãããã«ããããŒãšåŒã°ããCSSæ¬äŒŒã»ã¬ã¯ã¿ãŒã䜿çšãããšããã®ãããªå¹æãã¯ããã«ç°¡åã«éæã§ããããšã远å ããå¿
èŠããããŸãã ãã ãããããŒæã«ããŒãã®ã¹ã¿ã€ã«ã倿Žãããããè€éãªæäœãå¿
èŠãªå Žåã¯ãmouseoverã€ãã³ããšmouseoutã€ãã³ãã§ããªãã¯ã䜿çšããå¿
èŠããããŸãã
<style> p:hover { color: red } </style> <p> <strong> </strong>.</p>
ã¹ã¯ããŒã«ã€ãã³ã
ã¢ã€ãã ãã¹ã¯ããŒã«ãããšããã¹ã¯ããŒã«ãã€ãã³ããçºçããŸãã ããã¯å€ãã®å Žåã«äœ¿çšãããŸããããšãã°ããŠãŒã¶ãŒãèŠãŠãããã®ãèŠã€ããïŒç»é¢ã«è¡šç€ºãããªãã¢ãã¡ãŒã·ã§ã³ã忢ããããŸãã¯æªæã®ããæ¬éšã«ç§å¯ã®ã¹ãã€ã¬ããŒããéä¿¡ããïŒããŸãã¯é²è¡ç¶æ³ãèŠèŠçã«ç€ºãïŒã³ã³ãã³ãã®äžéšã匷調衚瀺ãããããŒãžçªå·ã衚瀺ããïŒããã«äœ¿çšãããŸãã
ãã®äŸã§ã¯ãããã¥ã¡ã³ãã®å³äžé
ã«ããã»ã¹ã€ã³ãžã±ãŒã¿ãäœæãããã¢ã€ãã ãäžã«ã¹ã¯ããŒã«ãããšå¡ãã€ã¶ãããŸãã
<style> .progress { border: 1px solid blue; width: 100px; position: fixed; top: 10px; right: 10px; } .progress > div { height: 12px; background: blue; width: 0%; } body { height: 2000px; } </style> <div class="progress"><div></div></div> <p>Scroll me...</p> <script> var bar = document.querySelector(".progress div"); addEventListener("scroll", function() { var max = document.body.scrollHeight - innerHeight; var percent = (pageYOffset / max) * 100; bar.style.width = percent + "%"; }); </script>
åºå®èŠçŽ ã®äœçœ®ã¯ã絶察èŠçŽ ãšã»ãŒåãããšãæå³ããŸãããããã¥ã¡ã³ãã®æ®ãã®éšåãšãšãã«èŠçŽ ãã¹ã¯ããŒã«ããã®ãé²ããŸãã ãã€ã³ãã¯ãã€ã³ãžã±ãŒã¿ãŒãé
ã«æ®ãããšã§ãã å
éšã«ã¯ãçŸåšã®é²è¡ç¶æ³ãåæ ããããã«ãµã€ãºå€æŽãããå¥ã®èŠçŽ ããããŸãã èŠçŽ ã®ãµã€ãºãã€ã³ãžã±ãŒã¿ãŒå
šäœã®ãµã€ãºã«å¯ŸããŠå€åããããã«ãpxã§ã¯ãªãããŒã»ã³ããŒãžã䜿çšããŠå¹
ãèšå®ããŸãã
ã°ããŒãã«å€æ°innerHeightã¯ãŠã£ã³ããŠã®é«ããæå®ããŸããããã¯ãã¹ã¯ããŒã«å¯èœãªèŠçŽ ã®å
šé«ããå·®ãåŒãå¿
èŠããããŸããèŠçŽ ã®æåŸã«å°éãããšãã¹ã¯ããŒã«ãçµäºããŸãã ïŒinnerHeightã«å ããŠã倿°innerWidthããããŸãïŒã pageYOffsetã®çŸåšã®ã¹ã¯ããŒã«äœçœ®ãæå€§ã¹ã¯ããŒã«äœçœ®ã§é€ç®ãã100åãããšãã€ã³ãžã±ãŒã¿ãŒã®ããŒã»ã³ããŒãžãåŸãããŸãã
preventDefaultãåŒã³åºããŠããã¹ã¯ããŒã«ã¯é²æ¢ãããŸããã ã€ãã³ããã³ãã©ã¯ãã¹ã¯ããŒã«ãçºçããåŸã«åŒã³åºãããŸãã
ãã©ãŒã«ã¹ã€ãã³ã
èŠçŽ ããã©ãŒã«ã¹ãåãåããšããã©ãŠã¶ã¯ãfocusãã€ãã³ããçºçãããŸãã ãã©ãŒã«ã¹ã倱ããšãããŒãããã€ãã³ããçºçããŸãã
以åã®ã€ãã³ããšã¯ç°ãªããããã2ã€ã¯å¯Ÿè±¡å€ã§ãã 芪ããŒãã®ãã³ãã©ãŒã¯ãåã«ãããã©ãŒã«ã¹ã®åä¿¡ãŸãã¯åªå€±ã«ã€ããŠéç¥ãããŸããã
次ã®äŸã¯ãçŸåšãã©ãŒã«ã¹ãããããã¹ããã£ãŒã«ãã®ããŒã«ãããããã¹ãã瀺ããŠããŸãã
<p>: <input type="text" data-help=" "></p> <p>: <input type="text" data-help=" "></p> <p id="help"></p> <script> var help = document.querySelector("#help"); var fields = document.querySelectorAll("input"); for (var i = 0; i < fields.length; i++) { fields[i].addEventListener("focus", function(event) { var text = event.target.getAttribute("data-help"); help.textContent = text; }); fields[i].addEventListener("blur", function(event) { help.textContent = ""; }); } </script>
ãŠãŒã¶ãŒãããã¥ã¡ã³ãã衚瀺ãããã©ãŠã¶ãŒã®ããã¯ããŒã¯ãŸãã¯ãã©ãŠã¶ãŒãŠã£ã³ããŠãããã©ãŒã«ã¹ãéžæãŸãã¯åé€ãããšããŠã£ã³ããŠãªããžã§ã¯ãã¯ãã©ãŒã«ã¹ã€ãã³ããšãã©ãŒã€ãã³ããåãåããŸãã
ã¢ããããŒãã€ãã³ã
ããŒãžã®èªã¿èŸŒã¿ãå®äºãããšããŠã£ã³ããŠãªããžã§ã¯ããšæ¬æãªããžã§ã¯ãã§ãloadãã€ãã³ããçºçããŸãã ããã¯ãå®å
šã«æ§ç¯ãããããã¥ã¡ã³ããå¿
èŠãšããåæåã¢ã¯ãã£ããã£ãèšç»ããããã«ãã䜿çšãããŸãã ã¿ã°ã®å
容ãæãåºããŠãã ãã
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); // Your code here. </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { /* className , */ position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> // . </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { // . } asTabs(document.querySelector("#wrapper")); </script>
, . â , - , .
, , âloadâ, , . , .
(, ), "beforeunload". â . , , preventDefault. . , , . , , , , .
. - . â . 13 requestAnimationFrame, . .
, , . , . , . , , .
. , . , .
, JavaScript , . - , , « » (web worker) â JavaScript, , .
, code/squareworker.js:
addEventListener("message", function(event) { postMessage(event.data * event.data); });
, â , , . «», , .
var squareWorker = new Worker("code/squareworker.js"); squareWorker.addEventListener("message", function(event) { console.log("The worker responded:", event.data); }); squareWorker.postMessage(10); squareWorker.postMessage(24);
postMessage , âmessageâ . , , Worker, , , â , .
setTimeout requestAnimationFrame. . , . :
<script> document.body.style.background = "blue"; setTimeout(function() { document.body.style.background = "yellow"; }, 2000); </script>
. , , setTimeout, clearTimeout.
var bombTimer = setTimeout(function() { console.log("BOOM!"); }, 500); if (Math.random() < 0.5) { // 50% chance console.log("Defused."); clearTimeout(bombTimer); }
cancelAnimationFrame , clearTimeout â , requestAnimationFrame, ( ).
, setInterval clearInterval , X .
var ticks = 0; var clock = setInterval(function() { console.log("tick", ticks++); if (ticks == 10) { clearInterval(clock); console.log("stop."); } }, 200);
(debouncing)
(, "mousemove" "scroll"). «», , .
- , setTimeout, , . « » . .
-, , . , , . , . , , (, ), .
<textarea> -...</textarea> <script> var textarea = document.querySelector("textarea"); var timeout; textarea.addEventListener("keydown", function() { clearTimeout(timeout); timeout = setTimeout(function() { console.log(" ."); }, 500); }); </script>
undefined clearTimeout, , , . , , .
, , , , . , "mousemove", , 250 .
<script> function displayCoords(event) { document.body.textContent = " " + event.pageX + ", " + event.pageY; } var scheduled = false, lastEvent; addEventListener("mousemove", function(event) { lastEvent = event; if (!scheduled) { scheduled = true; setTimeout(function() { scheduled = false; displayCoords(lastEvent); }, 250); } }); </script>
, . addEventListener.
("keydown", "focus", ). DOM, , .
. , (stopPropagation) (preventDefault).
"keydown", "keypress" "keyup". "mousedown", "mouseup" "click". "mousemove", "mouseenter" "mouseout".
âscrollâ, "focus" "blur". , window âloadâ.
. .
1928 2013 Q, W X . â , .
, , . .
<input type="text"> <script> var field = document.querySelector("input"); </script>
JavaScript, , . « » - , .
, . , . .
. , . â , , "mousemove".
<style> .trail { position: absolute; height: 6px; width: 6px; border-radius: 3px; background: teal; } body { height: 300px; } </style> <script> </script>
. , .
. asTabs, DOM, , . , , , data-tabname. , , ( display style none), .
, , .
<div id="wrapper"> <div data-tabname="one"> </div> <div data-tabname="two"> </div> <div data-tabname="three"> </div> </div> <script> function asTabs(node) { </script>