ãã®è³æã®èè ã¯ã SessionStackãã¬ã³ããªã³ã°ã«å€å€§ãªæ³šæãæãå¿ èŠããããšè¿°ã¹ãŠããŸãã ãã®èšäºã§ã¯ãèŠèŠåã®æ©èœãèæ ®ããŠãWebããŒãžã®æé©åã«é¢ãããã³ããå ±æããŸãã
[ã¢ããã€ã¹ãèªã]ãµã€ã¯ã«ã®ä»ã®19ã®éšå
ããŒã1ïŒ ãšã³ãžã³ãã©ã³ã¿ã€ã ã¡ã«ããºã ãã³ãŒã«ã¹ã¿ãã¯ã®æŠèŠ
ããŒã2ïŒ V8å éšãšã³ãŒãã®æé©åã«ã€ããŠ
ããŒã3ïŒ ã¡ã¢ãªç®¡çã4çš®é¡ã®ã¡ã¢ãªãªãŒã¯ãããã³ããããšã®æŠã
ããŒã4ïŒ ã€ãã³ãã«ãŒããéåæãããã³éåæ/åŸ æ©ã䜿çšããŠã³ãŒããæ¹åãã5ã€ã®æ¹æ³
ããŒã5ïŒ WebSocketãšHTTP / 2 + SSEã äœãéžã¶ïŒ
ããŒã6ïŒ WebAssemblyã®æ©èœãšç¯å²
ããŒã7ïŒ Web Workersãš5ã€ã®äœ¿çšã·ããªãª
ããŒã8ïŒ ãµãŒãã¹ã¯ãŒã«ãŒ
ããŒã9ïŒ Webããã·ã¥éç¥
ããŒã10ïŒ MutationObserverã䜿çšããŠDOMã®å€æŽã远跡ãã
ããŒã11ïŒ WebããŒãžã¬ã³ããªã³ã°ãšã³ãžã³ãšããã©ãŒãã³ã¹ãæé©åããããã®ãã³ã
ããŒã12ïŒ ããã©ãŒãã³ã¹ãšã»ãã¥ãªãã£ãæé©åãããã©ãŠã¶ãŒã®ãããã¯ãŒã¯ãµãã·ã¹ãã
ããŒã12ïŒ ããã©ãŒãã³ã¹ãšã»ãã¥ãªãã£ãæé©åãããã©ãŠã¶ãŒã®ãããã¯ãŒã¯ãµãã·ã¹ãã
ããŒã13ïŒ CSSãšJavaScriptã䜿çšããã¢ãã¡ãŒã·ã§ã³
ããŒã14ïŒ JSã®ä»çµã¿ïŒæœè±¡æ§æããªãŒã解æãããã³ãã®æé©å
ããŒã15ïŒ JSã®ä»çµã¿ïŒã¯ã©ã¹ãšç¶æ¿ãBabelããã³TypeScriptã§ã®ãã©ã³ã¹ãã¬ãŒã·ã§ã³
ããŒã16ïŒ JSã®ä»çµã¿ïŒã¹ãã¬ãŒãž
ããŒã17ïŒ JSã®ä»çµã¿ïŒShadow DOMãã¯ãããžãŒãšWebã³ã³ããŒãã³ã
ããŒã18ïŒ JSã®ä»çµã¿ïŒWebRTCããã³P2Péä¿¡ã¡ã«ããºã
ããŒã19ïŒ JSã®ä»çµã¿ïŒã«ã¹ã¿ã èŠçŽ
ããŒã2ïŒ V8å éšãšã³ãŒãã®æé©åã«ã€ããŠ
ããŒã3ïŒ ã¡ã¢ãªç®¡çã4çš®é¡ã®ã¡ã¢ãªãªãŒã¯ãããã³ããããšã®æŠã
ããŒã4ïŒ ã€ãã³ãã«ãŒããéåæãããã³éåæ/åŸ æ©ã䜿çšããŠã³ãŒããæ¹åãã5ã€ã®æ¹æ³
ããŒã5ïŒ WebSocketãšHTTP / 2 + SSEã äœãéžã¶ïŒ
ããŒã6ïŒ WebAssemblyã®æ©èœãšç¯å²
ããŒã7ïŒ Web Workersãš5ã€ã®äœ¿çšã·ããªãª
ããŒã8ïŒ ãµãŒãã¹ã¯ãŒã«ãŒ
ããŒã9ïŒ Webããã·ã¥éç¥
ããŒã10ïŒ MutationObserverã䜿çšããŠDOMã®å€æŽã远跡ãã
ããŒã11ïŒ WebããŒãžã¬ã³ããªã³ã°ãšã³ãžã³ãšããã©ãŒãã³ã¹ãæé©åããããã®ãã³ã
ããŒã12ïŒ ããã©ãŒãã³ã¹ãšã»ãã¥ãªãã£ãæé©åãããã©ãŠã¶ãŒã®ãããã¯ãŒã¯ãµãã·ã¹ãã
ããŒã12ïŒ ããã©ãŒãã³ã¹ãšã»ãã¥ãªãã£ãæé©åãããã©ãŠã¶ãŒã®ãããã¯ãŒã¯ãµãã·ã¹ãã
ããŒã13ïŒ CSSãšJavaScriptã䜿çšããã¢ãã¡ãŒã·ã§ã³
ããŒã14ïŒ JSã®ä»çµã¿ïŒæœè±¡æ§æããªãŒã解æãããã³ãã®æé©å
ããŒã15ïŒ JSã®ä»çµã¿ïŒã¯ã©ã¹ãšç¶æ¿ãBabelããã³TypeScriptã§ã®ãã©ã³ã¹ãã¬ãŒã·ã§ã³
ããŒã16ïŒ JSã®ä»çµã¿ïŒã¹ãã¬ãŒãž
ããŒã17ïŒ JSã®ä»çµã¿ïŒShadow DOMãã¯ãããžãŒãšWebã³ã³ããŒãã³ã
ããŒã18ïŒ JSã®ä»çµã¿ïŒWebRTCããã³P2Péä¿¡ã¡ã«ããºã
ããŒã19ïŒ JSã®ä»çµã¿ïŒã«ã¹ã¿ã èŠçŽ
埩ç¿
Webã¢ããªã±ãŒã·ã§ã³ãäœæããéãç§ãã¡ã¯ç¬èªã®ãå éšãã®åé¡ãæä»çã«æ±ãç¬ç«ããJSã³ãŒããäœæããŸããã ãã®ã³ãŒãã¯ããã©ãŠã¶ãæäŸããç°å¢ã§å®è¡ããã察話ããŸãã ãã®ç°å¢ã®ããã€ã¹ãåäœæ¹æ³ãæ§æèŠçŽ ãç解ããããšã«ãããéçºè ã¯ããåªããããã°ã©ã ãäœæã§ããã¢ããªã±ãŒã·ã§ã³ã§çºçããå¯èœæ§ã®ããåé¡ã®çºçãäºæž¬ããæ©äŒãåŸãããŸãã
次ã®å³ã¯ããã©ãŠã¶ã®äž»èŠã³ã³ããŒãã³ãã瀺ããŠããŸãã WebããŒãžã®åŠçã§åœŒããæãã圹å²ã«ã€ããŠè©±ããŸãããã
äž»èŠãªãã©ãŠã¶ã³ã³ããŒãã³ã
- ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ãŒã¹ ãã®ãã©ãŠã¶ã³ã³ããŒãã³ãã«ã¯ãã¢ãã¬ã¹ããŒããé²ããããã³ãæ»ãããã¿ã³ãããã¯ããŒã¯ãæäœããããã®ã³ãã³ããªã©ãå«ãŸããŸãã äžè¬ã«ãããã¯ãã©ãŠã¶ã衚瀺ãããã¹ãŠã§ã-衚瀺ããWebããŒãžãé
眮ãããŠãããŠã£ã³ããŠã®é åãé€ããŸãã
- ãã©ãŠã¶ãšã³ãžã³ 圌ã¯ããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãšã¬ã³ããªã³ã°ãšã³ãžã³éã®çžäºäœçšããµããŒããã責任ããããŸãã
- ã¬ã³ããªã³ã°ãšã³ãžã³ ãã®ãµãã·ã¹ãã ã¯ãWebããŒãžã®è¡šç€ºãæ
åœããŸãã ã¬ã³ããªã³ã°ãšã³ãžã³ã¯HTMLãšCSSãåŠçããç»é¢ã«è¡šç€ºããŸãã
- ãããã¯ãŒã¯ãµãã·ã¹ãã ïŒãããã¯ãŒãã³ã°ïŒã ãã®ãµãã·ã¹ãã ã¯ããã©ãŠã¶ãšå€çãšã®ãããã¯ãŒã¯çžäºäœçšãæ
åœããŸããç¹ã«ãããšãã°ãXHRèŠæ±ã¯ãã®æ段ã«ãã£ãŠå®è¡ãããŸãã ãã©ãããã©ãŒã ã«äŸåããªãã€ã³ã¿ãŒãã§ã€ã¹ããµããŒãããç°ãªããã©ãããã©ãŒã ã«åºæã®ããŸããŸãªãããã¯ãŒã¯ã¡ã«ããºã ã®ç¹å®ã®å®è£
ãé ããŸãã ããã§ã¯ããã®ãµãã·ã¹ãã ã«é¢ãã詳现ãèªãããšãã§ããŸãã
- ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãµããŒããµãã·ã¹ãã ïŒUIããã¯ãšã³ãïŒã ãã®ãµãã·ã¹ãã ã¯ããŠã£ã³ããŠããã§ãã¯ããã¯ã¹ãªã©ã®ã³ã³ãããŒã«ãªã©ã®åºæ¬çãªã€ã³ã¿ãŒãã§ã€ã¹ã³ã³ããŒãã³ãã衚瀺ããŸãã ããã§ããã©ãŠã¶ã«ã¯ãåäœãããã©ãããã©ãŒã ã«äŸåããªããŠãããŒãµã«ã€ã³ã¿ãŒãã§ã€ã¹ãæäŸãããŸãããã®ãµãã·ã¹ãã ã¯ãç¹å®ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«ãã£ãŠæäŸããããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹èŠçŽ ã圢æããå¯èœæ§ã«åºã¥ããŠããŸãã
- JavaScriptãšã³ãžã³ïŒJavaScriptãšã³ãžã³ïŒã ãã®ã·ãªãŒãºã®ä»¥åã®è³æã® 1ã€ã§JSãšã³ãžã³ãåæããŸããã ããã§ãJSã³ãŒããå®è¡ãããŸãã
- æ°žç¶çãªããŒã¿ã¹ãã¬ãŒãžã®ãµãã·ã¹ãã ïŒããŒã¿æ°žç¶æ§ïŒã ã¢ããªã±ãŒã·ã§ã³ãããŒã«ã«ã¹ãã¬ãŒãžæ©èœãå¿
èŠãšããå Žåããã®ãµãã·ã¹ãã ãæäŸããããŸããŸãªã¡ã«ããºã ã䜿çšã§ããŸãã ããšãã°ã localStorage ã IndexedDB ã WebSQLã FileSystemãªã©ã®APIã
ãã®èšäºã§ã¯ãã¬ã³ããªã³ã°ãšã³ãžã³ã«çŠç¹ãåœãŠãŸãã HTMLãšCSSã解æããã³ã¬ã³ããªã³ã°ããã®ã¯ããã®ãã©ãŠã¶ãŒãµãã·ã¹ãã ã§ãã ãããŠããããã¯ãŸãã«JavaScriptã§æžãããWebã¢ããªã±ãŒã·ã§ã³ã³ãŒããåžžã«ããåããããã¯ãããžãŒã§ãã
ããŸããŸãªã¬ã³ããªã³ã°ãšã³ãžã³ã«ã€ããŠ
ã¬ã³ããªã³ã°ãšã³ãžã³ã®äž»ãªã¿ã¹ã¯ã¯ãèŠæ±ãããããŒãžããã©ãŠã¶ãŠã£ã³ããŠã«è¡šç€ºããããšã§ãã ãšã³ãžã³ã¯ãHTMLããã¥ã¡ã³ããXMLããã¥ã¡ã³ããç»åãåºåã§ããŸãã è¿œå ã®ãã©ã°ã€ã³ã䜿çšããŠããšã³ãžã³ã¯PDFããã¥ã¡ã³ããªã©ãä»ã®çš®é¡ã®ãããªã¢ã«ãèŠèŠåããããšãã§ããŸãã
ããŸããŸãªãã©ãŠã¶ãŒã䜿çšããããŸããŸãªJSãšã³ãžã³ãããããšãããã£ãŠããŸãã åãããšãã¬ã³ããªã³ã°ãšã³ãžã³ã«ãåœãŠã¯ãŸããŸãã 人æ°ã®ãããšã³ãžã³ã¯æ¬¡ã®ãšããã§ãã
- Gecko-Firefoxãã©ãŠã¶ãŒã§äœ¿çšãããŸãã
- WebKit-Safariãã©ãŠã¶ãŒã§äœ¿çšãããŸãã
- ç¹æ»
-Chromeããã³Operaãã©ãŠã¶ãŒã«çµ±åïŒ15çªç®ã®ããŒãžã§ã³ããïŒã
WebããŒãžã®ã¬ã³ããªã³ã°ããã»ã¹
ã¬ã³ããªã³ã°ãšã³ãžã³ã¯ãèŠæ±ãããããã¥ã¡ã³ãã®ã³ã³ãã³ãããã©ãŠã¶ã®ãããã¯ãŒã¯ã¬ãã«ããåãåããŸãã ã¬ã³ããªã³ã°ããã»ã¹ã¯æ¬¡ã®ç»åã®ããã«ãªããŸãã
WebããŒãžã®ã¬ã³ããªã³ã°ããã»ã¹
ãã®ããã»ã¹ã®äž»ãªæé ã¯æ¬¡ã®ãšããã§ãã
- DOMããªãŒãäœæããããã®HTMLåŠçã
- ã¬ã³ããªã³ã°ããªãŒãäœæããŸãã
- ç»é¢äžã®ã¬ã³ããªã³ã°ããªãŒèŠçŽ ã®å Žæãã©ã¡ãŒã¿ãŒã®èšç®ãããŒãžã¬ã€ã¢ãŠãã®åœ¢æã
- ã¬ã³ããªã³ã°ããªãŒã®èŠèŠåïŒã¬ã³ããªã³ã°ïŒã
WebããŒãžãã¬ã³ããªã³ã°ãããšãã«å®è¡ããããããã®ã¹ãããããã³ãã®ä»ã®ã¹ãããã«ã€ããŠããã詳现ã«æ€èšããŠãã ããã
DOMããªãŒã®äœæ
ã¬ã³ããªã³ã°ãšã³ãžã³ã®æåã®æ®µéã§ã¯ãHTMLããã¥ã¡ã³ãã解æãããã®åŠçãDOMããªãŒã§ãã¹ããããŠããDOMããŒãã«å€æããŸãã åæã«ãHTMLã³ãŒãã®åœ¢åŒã§è¡šç€ºãããWebããŒãžã¯ã次ã®å³ã«ç€ºããããªæ§é ã«å€æãããŸãã
DOMããªãŒ
ãã¹ããããèŠçŽ ãå«ããã®ããªãŒã®åèŠçŽ ã¯ããããã®èŠªã§ãã ããã¯ããã¹ãã®ãã¹ãŠã®ã¬ãã«ã«åœãŠã¯ãŸããŸãã
CSSOMããªãŒã®äœæ
CSSOMïŒCSS Object ModelïŒã¯ãCSSãªããžã§ã¯ãã¢ãã«ã§ãã ãã©ãŠã¶ãããŒãžã®DOMããªãŒãäœæãããšã
head
ã»ã¯ã·ã§ã³ã§ãããšãã°
theme.css
ãšããååã®å€éšCSSãã¡ã€ã«ãåç §ãã
link
ã¿ã°ãèŠã€ã
theme.css
ã ãã©ãŠã¶ã¯ãããŒãžãã¬ã³ããªã³ã°ããããã«ãã®ãªãœãŒã¹ãå¿ èŠã«ãªãå¯èœæ§ããããšäºæ³ããŠããã®ãã¡ã€ã«ãããŠã³ããŒãããèŠæ±ãå®è¡ããŸãã ãã®ãã¡ã€ã«ã«ã¯ãããŒãžèŠçŽ ã«é©çšãããã¹ã¿ã€ã«ã®èª¬æã§ãããã¬ãŒã³ããã¹ããå«ãŸããŠããŸãã
HTMLã®å Žåãšåæ§ã«ããšã³ãžã³ã¯CSSããã©ãŠã¶ãŒãæäœã§ãããã®ã«å€æããå¿ èŠããããŸã-CSSOMã§ã çµæã¯ã次ã®å³ã«ç€ºãCSSOMããªãŒã§ãã
CSSOMããªãŒ
CSSOMãããªãŒæ§é ãæã£ãŠããçç±ãç¥ã£ãŠããŸããïŒ ããŒãžèŠçŽ ã®ã¹ã¿ã€ã«ã®æçµã»ãããçæããããšããã©ãŠã¶ã¯DOMããŒãã§è¡šããããã®èŠçŽ ã«é©çšå¯èœãªæãäžè¬çãªã«ãŒã«ã§éå§ãïŒããšãã°ãããŒãã
body
èŠçŽ ã®åå«ã§ããå Žåã
body
æå®ããããã¹ãŠã®ã¹ã¿ã€ã«ãããã«é©çšãããŸãïŒãååž°çã«çµã蟌ã¿ãŸãããå ·äœçãªã«ãŒã«ã䜿çšããŠèšç®ãããã¹ã¿ã€ã«ã
åã®å³ã«ç€ºããäŸã調ã¹ãŠã¿ãŸãããã
body
èŠçŽ ã«é 眮ããã
span
ã¿ã°å ã«å«ãŸããããã¹ãã¯ãã¹ãŠèµ€ã§è¡šç€ºããããã©ã³ããµã€ãºã¯
16px
ã§ãã ãããã®ã¹ã¿ã€ã«ã¯ã
body
èŠçŽ ããç¶æ¿ãããŸãã
span
èŠçŽ ã
p
èŠçŽ ã®åå«ã§ããå Žåããã®å 容ã¯ãé©çšãããããå ·äœçãªã¹ã¿ã€ã«ã«åŸã£ãŠè¡šç€ºãããŸããã
ãŸããäžèšã®ããªãŒã¯å®å šãªCSSOMããªãŒã§ã¯ãªãããšã«æ³šæããŠãã ããã CSSãã¡ã€ã«ã§åå®çŸ©ããããšã«ããã¹ã¿ã€ã«ã®ã¿ã瀺ããŠããŸãã åãã©ãŠã¶ã«ã¯ãããŠãŒã¶ãŒãšãŒãžã§ã³ãã¹ã¿ã€ã«ããšãåŒã°ããããã©ã«ãã®ããã©ã«ãã®ã¹ã¿ã€ã«ã»ããããããŸãã ãããã®ã¹ã¿ã€ã«ãé©çšããçµæã¯ãCSSã«ãŒã«ãé¢é£ä»ããããŠããªãããŒãžã§èŠãããšãã§ããŸãã ç§ãã¡ã®ã¹ã¿ã€ã«ã¯ãæšæºçãªãã©ãŠã¶ã¹ã¿ã€ã«ã®äžéšãåå®çŸ©ããã ãã§ãã
ã¬ã³ããªã³ã°ããªãŒãäœæãã
HTMLã§è¡šç€ºãããèŠçŽ ã®å€èŠ³ã«é¢ããæ瀺ã¯ãCSSOMããªãŒããã®ã¹ã¿ã€ãªã³ã°ã«é¢ããæ å ±ãšçµã¿åãããŠãã¬ã³ããªã³ã°ããªãŒã圢æããããã«äœ¿çšãããŸãã
ããã¯äœã§ãã ããã¯ãç»é¢ã«è¡šç€ºãããé åºã§äœæãããèŠèŠèŠçŽ ã®ããªãŒã§ãã ããã¯ããŒãžã®HTMLã³ãŒãã®èŠèŠçè¡šçŸã§ããããã®ããŒãžã«å¯Ÿå¿ããCSSã«ãŒã«ã®åœ±é¿ãåæ ããŠããŸãã ãã®ããªãŒã®ç®çã¯ãèŠçŽ ãæ£ããé åºã§è¡šç€ºãããããã«ããããšã§ãã
ã¬ã³ããªã³ã°ããªãŒããŒãã¯ãWebKitãšã³ãžã³ã§ã¯ãã¬ã³ãã©ãŒããŸãã¯ãã¬ã³ããŒãªããžã§ã¯ãããšããŠç¥ãããŠããŸãïŒãã¬ã³ããŒãªããžã§ã¯ãããšåŒã³ãŸãïŒã
äžèšã®DOMããªãŒãšCSSOMããªãŒã®ã¬ã³ããŒããªãŒã¯æ¬¡ã®ããã«ãªããŸãã
ã¬ã³ããŒããªãŒ
以äžã¯ãã¬ã³ããŒããªãŒãäœæãããšãã«å®è¡ãããã©ãŠã¶ã¢ã¯ã·ã§ã³ã®äžè¬çãªèª¬æã§ãã
- DOMããªãŒã®ã«ãŒãããå§ãŸãããã©ãŠã¶ã¯è¡šç€ºãããŠãããã¹ãŠã®ããŒããèµ°æ»ããŸãã äžéšã®ãµã€ãã¯äžå¯èŠã§ããïŒããšãã°ãã¹ã¯ãªãããžã®ãªã³ã¯ãå«ãã¿ã°ãã¡ã¿ã¿ã°ãªã©ïŒãããŒãžã®å€èŠ³ã«åœ±é¿ããªãããããã©ãŠã¶ãŒã¯ã¹ãããããŸãã äžéšã®ããŒãã¯CSSã«ãã£ãŠé衚瀺ã«ãªããŸããããã©ãŠã¶ãŒãã¬ã³ããªã³ã°ããªãŒã«ããããå«ããŸããã ããšãã°ããã®äŸã®
span
ããŒãã¯ãdisplay: none
ãèšå®ããæ瀺çãªã«ãŒã«ããããããã¬ã³ããªã³ã°ããªãŒã«ã¯è¡šç€ºãããŸããdisplay: none
ããããã£ã
- 衚瀺ãããŠããåããŒãã«ã€ããŠããã©ãŠã¶ã¯é©åãªCSSOMã«ãŒã«ãèŠã€ããŠé©çšããŸãã
- ãã®çµæãå¯èŠããŒããšãããã®ããã«èšç®ãããã¹ã¿ã€ã«ãå«ãæ§é ã圢æãããŸãã
ããã§äœãåé¡ãªã®ããããããç解ããããã«ãWebKitã®RenderObjectã¯ã©ã¹ã®ãœãŒã¹ã³ãŒããèŠãããšãã§ããŸãã åã¬ã³ããªã³ã°ãªããžã§ã¯ãã¯ãéåžžã¯ããŒãã®CSSãããã¯ã«å¯Ÿå¿ããé·æ¹åœ¢ã®é åã§ãã ãã®ãããã¯ã«é¢ããæ å ±ã«ã¯ãå¹ ãé«ããäœçœ®ãªã©ã®å¹ŸäœåŠçç¹æ§ãå«ãŸããŸãã
ããŒãžã¬ã€ã¢ãŠã
ã¬ã³ããªã³ã°ãªããžã§ã¯ããäœæãããŠããªãŒã«è¿œå ãããåŸã¯ããŸã äœçœ®ãšãµã€ãºãå²ãåœãŠãããŠããŸããã ãããã®å€ã®èšç®ã¯ãããŒãžã¬ã€ã¢ãŠãã®åœ¢æãšåŒã°ããŸãã
HTMLã¯ã¹ããªãŒãã³ã°ã¬ã€ã¢ãŠãã¢ãã«ã䜿çšããŸãã ããã¯ãã»ãšãã©ã®å Žåãã·ã¹ãã ã1åã®ãã¹ã§èŠçŽ ã®å¹ŸäœåŠçãã©ã¡ãŒã¿ãŒãèšç®ã§ããããšãæå³ããŸãã ããã¯ãã«ãŒãã¬ã³ããªã³ã°ãªããžã§ã¯ãã«åºã¥ã座æšç³»ã䜿çšãã
left
ãš
top
座æšã䜿çšããŸãã
ã¬ã€ã¢ãŠãã¯ååž°çãªããã»ã¹ã§ãã
<html>
ããã¥ã¡ã³ãã®èŠçŽ ã«å¯Ÿå¿ããã«ãŒããªããžã§ã¯ãããå§ãŸããŸãã ãã®ããã»ã¹ã¯ãã¬ã³ããªã³ã°ãªããžã§ã¯ãã®éå±€æ§é å šäœã§ååž°çã«å®è¡ãããå¿ èŠãªåèŠçŽ ã®ãµã€ãºãšäœçœ®ãèšç®ãããŸãã
ã«ãŒãã¬ã³ããªã³ã°ãªããžã§ã¯ãã®äœçœ®ã¯
0,0
ã§ãã ãã®å¯žæ³ã¯ããã©ãŠã¶ãŠã£ã³ããŠã®å¯èŠéšåã®å¯žæ³ã«å¯Ÿå¿ããŸãïŒããã¯ã衚瀺é åãããã¥ãŒããŒããšåŒã°ããŸãïŒã
ã¬ã€ã¢ãŠããäœæããããã»ã¹ãšã¯ãããŒãžäžã«è¡šç€ºããæ£ç¢ºãªäœçœ®ãåããŒãã«å²ãåœãŠãããšã§ãã
ã¬ã³ããŒããªãŒã¬ã³ããŒ
ãã®æ®µéã§ãã¬ã³ããªã³ã°ããªãŒããã©ããŒã¹ãããã¬ã³ããªã³ã°ãªããžã§ã¯ãã®
paint()
ã¡ãœãããåŒã³åºãããç»é¢äžã®ãªããžã§ã¯ãã®ã°ã©ãã£ãã¯è¡šçŸã®åºåãå®è¡ãããŸãã
èŠèŠåããŸãã¯ã¬ã³ããªã³ã°ã¯ãã°ããŒãã«ãŸãã¯ã€ã³ã¯ãªã¡ã³ã¿ã«ã§ãïŒããŒãžã¬ã€ã¢ãŠãã®åœ¢æãå®è¡ãããŸãïŒã
- ã°ããŒãã«ã¬ã³ããªã³ã°ãšã¯ãã¬ã³ããªã³ã°ããªãŒå
šäœãåã¬ã³ããªã³ã°ããããšã§ãã
- ã€ã³ã¯ãªã¡ã³ã¿ã«ã¬ã³ããªã³ã°ã¯ãã¬ã³ããªã³ã°ãªããžã§ã¯ãã®äžéšã®ã¿ãå€æŽãããããªãŒå
šäœã«åœ±é¿ãäžããªãç¶æ³ã§å®è¡ãããŸãã ã¬ã³ããªã³ã°ãµãã·ã¹ãã ã¯ãç»é¢äžã®é·æ¹åœ¢ã®é åãç¡å¹ã«ããŸãã ããã¯ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ããããããã³ã³ãã³ããæŽæ°ããå¿
èŠãããé åãšããŠèªèãã
paint
ã€ãã³ããçæãããšããäºå®ã«ã€ãªãããŸãã ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¯ãè€æ°ã®é åã1ã€ã«çµåããããšã§ãé åãã€ã³ããªãžã§ã³ãã«åæç»ããŸãã
äžè¬ã«ãèŠèŠåã¯æ®µéçãªããã»ã¹ã§ããããšãç解ããããšãéèŠã§ãã ããŒãžã®ãŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ãåäžããããããã¬ã³ããªã³ã°ãšã³ãžã³ã¯ãã§ããã ãæ©ãããŒãžãç»é¢ã«è¡šç€ºããããšãç®æããŠããŸãã 圌ã¯ãã¬ã³ããªã³ã°ããªãŒã®åœ¢æãšããŒãžã¬ã€ã¢ãŠããã©ã¡ãŒã¿ãŒã®èšç®ãé²ããããã«ããã¹ãŠã®HTMLã解æããããŸã§åŸ æ©ããŸããã ãã®çµæãããŒãžã®äžéšãåŠçãããŠç»é¢ã«è¡šç€ºãããŸãããã¬ã³ããªã³ã°ãšã³ãžã³ã¯ãããã¯ãŒã¯ããéãããŠããããŒãžã®æ®ãã®ã³ã³ãã³ããåŒãç¶ã䜿çšããŸãã
JSã¹ã¯ãªãããšCSSãã¡ã€ã«ãåŠçããæé
ã¹ã¯ãªããã¯ãããŒãžã³ãŒãåŠçã·ã¹ãã ã
<script>
å°éããçŽåŸã«è§£æããã³å®è¡ãããŸãã ã¹ã¯ãªãããå®è¡ããããŸã§ãããã¥ã¡ã³ãã®åŠçã¯äžæãããŸãã ããã¯ãããã»ã¹ãåæçã«å®è¡ãããŠããããšãæå³ããŸãã
ã¹ã¯ãªãããå€éšãœãŒã¹ããåä¿¡ããå Žåãæåã«ãããã¯ãŒã¯çµç±ã§ïŒåæçã«ïŒããŠã³ããŒãããå¿ èŠããããŸãã ããŒãžã®åŠçã¯ãã¹ã¯ãªããã®èªã¿èŸŒã¿ãå®äºãããŸã§äžæåæ¢ãããŸãã
HTML5ã§ã¯ãå¥ã®ã¹ããªãŒã ã䜿çšããŠãã¹ã¯ãªãããéåæã§ããŒãããã³åŠçããæ©èœã瀺ãããšãã§ããŸãã
ã¬ã³ããªã³ã°ããã©ãŒãã³ã¹ã®æé©å
ããŒãžã¬ã³ããªã³ã°ã®ç¹æ§ãèæ ®ããŠã¢ããªã±ãŒã·ã§ã³ãæé©åããå Žåã¯ã5ã€ã®äž»ãªé åãå¶åŸ¡ã§ããŸããã泚æãå¿ èŠãªé åããããŸãã
- Javascript ãã®ã·ãªãŒãºã®ä»¥åã®èšäºã§ã¯ããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ããããã¯ãããã¡ã¢ãªãå¹ççã«äœ¿çšããä»ã®æçšãªææ³ãå®è£
ããæé©åãããJSã³ãŒããèšè¿°ããæ¹æ³ã«ã€ããŠèª¬æããŸããã ã¬ã³ããªã³ã°ã«é¢ããŠã¯ãJSã³ãŒããããŒãžäžã®DOMèŠçŽ ãšã©ã®ããã«çžäºäœçšããããèæ
®ããå¿
èŠããããŸãã JavaScriptã¯ãç¹ã«åäžããŒãžã®ã¢ããªã±ãŒã·ã§ã³ã®å ŽåããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã«å€ãã®å€æŽãå ããããšãã§ããŸãã
- ã¹ã¿ã€ã«ã®èšç®ã ããã¯ãç¹å®ã®èŠçŽ ã«å¯Ÿå¿ããã»ã¬ã¯ã¿ãŒãèæ
®ããŠãç¹å®ã®èŠçŽ ã«é©çšãããCSSã«ãŒã«ã決å®ããããã»ã¹ã§ãã ã«ãŒã«ãå®çŸ©ããåŸãããããé©çšãããçµæã®ã¹ã¿ã€ã«ãåèŠçŽ ã«å¯ŸããŠèšç®ãããŸãã
- ããŒãžã¬ã€ã¢ãŠãã®åœ¢æã ãã©ãŠã¶ãŒã¯ãèŠçŽ ã«é©çšãããŠããã¹ã¿ã€ã«ãæ€åºãããšããã®èŠçŽ ãå ããç»é¢äžã®ã¹ããŒã¹ã®éãèšç®ãããã®äœçœ®ãèŠã€ããããšãã§ããŸãã WebããŒãžã¬ã€ã¢ãŠãã¢ãã«ã¯ãäžéšã®èŠçŽ ãä»ã®èŠçŽ ã«åœ±é¿ãåãŒãå¯èœæ§ãããããšã瀺ããŸãã ããšãã°ã
<body>
èŠçŽ ã®å¹ ã¯ãåèŠçŽ ã®å¹ ãªã©ã«åœ±é¿ããå ŽåããããŸãã ããã¯ãã¹ãŠãã¬ã€ã¢ãŠãã圢æããããã»ã¹ãéäžçãªèšç®ãå¿ èŠãšããã¿ã¹ã¯ã§ããããšãæå³ããŸãã ããã«ãèŠçŽ ã®åºåã¯å€ãã®ã¬ã€ã€ãŒã§å®è¡ãããŸãã
- ã¬ã³ããªã³ã°ã ããã§ã以åã«èšç®ããããã¹ãŠã®ãã®ããç»é¢ã«è¡šç€ºããããã¯ã»ã«ã«å€æãããŸãã ãã®ããã»ã¹ã«ã¯ãããã¹ããè²ãç»åãå¢çç·ã圱ãªã©ã®åºåãå«ãŸããŸãã ããã¯åèŠçŽ ã®ãã¹ãŠã®ç®ã«èŠããéšåã«ã€ããŠã§ãã
- ã¬ã€ã¢ãŠãã ããŒãžã®äžéšã¯ç°ãªãã¬ã€ã€ãŒã«è¡šç€ºãããå¯èœæ§ããããããæ£ããé åºã§åäžã®ãŠã£ã³ããŠã«çµåããå¿
èŠããããæ£ããããŒãžåºåã«ã€ãªãããŸãã ããã¯ãç¹ã«èŠçŽ ãéè€ããå Žåã«éåžžã«éèŠã§ãã
JSã³ãŒãã®æé©å
JavaScriptã³ãŒãã¯ãå€ãã®å Žåããã©ãŠã¶ã§èŠ³å¯ã§ãããã®ã«å€åããããããŸãã ããã¯ãç¹ã«åäžããŒãžã®ã¢ããªã±ãŒã·ã§ã³ã«åœãŠã¯ãŸããŸãã ããŒãžã¬ã³ããªã³ã°ããã»ã¹ãæ¹åããããã«JSãæé©åããããã®ãã³ãã次ã«ç€ºããŸãã
-
setTimeout()
ããã³setInterval()
é¢æ°ã䜿çšããŠããŒãžèŠçŽ ã®å€èŠ³ãæŽæ°ããªãã§ãã ããã ãããã®é¢æ°ã¯ããã¬ãŒã ã®åœ¢æã®ããæç¹ã§ãããããæåŸã«ã³ãŒã«ããã¯ãåŒãèµ·ãããŸãã ãã¬ãŒã ã®å é ã§èŠèŠçãªå€åãããããã³ãã³ããåŒã³åºããŠãèŠéããªãããã«ããå¿ èŠããããŸãã
- é·ãèšç®ãWebã¯ãŒã«ãŒã«è»¢éããŸã ã
- è€æ°ã®ãã¬ãŒã ã«åå²ããããã€ã¯ãã¿ã¹ã¯ã䜿çšããŠãDOMã«å€æŽãå ããŸãã ããã¯ãã¿ã¹ã¯ãDOMãžã®ã¢ã¯ã»ã¹ãå¿
èŠãšããWebã¯ãŒã«ãŒããã®DOMãžã®ã¢ã¯ã»ã¹ãååŸã§ããªãå Žåãªã©ã«äœ¿çšããå¿
èŠããããŸãã ããã¯ã倧ããªã¿ã¹ã¯ãå°ããªã¿ã¹ã¯ã«åå²ããã¿ã¹ã¯ã®ç¹æ§ã«å¿ããŠ
requestAnimationFrame
ãsetTimeout
ããŸãã¯setInterval
å ã§å®è¡ããå¿ èŠãããããšãæå³ããŸãã
CSSã®æé©å
èŠçŽ ã®è¿œå ãšåé€ãå±æ§ã®å€æŽããã®ä»ã®åæ§ã®ã¢ã¯ã·ã§ã³ã«ããDOMã®å€æŽã«ããããã©ãŠã¶ãŒã¯èŠçŽ ã®ã¹ã¿ã€ã«ãå€ãã®å ŽåãããŒãžå šäœã®ã¬ã€ã¢ãŠãããŸãã¯å°ãªããšããã®äžéšãåã«ãŠã³ãããå¿ èŠããããŸãã ããŒãžã®ã¬ã³ããªã³ã°ããã»ã¹ãæé©åããã«ã¯ã次ã®ããšãèæ ®ããŠãã ããã
- ã»ã¬ã¯ã¿ãŒã®è€éãã軜æžããŸãã è€éãªã»ã¬ã¯ã¿ãŒã䜿çšãããšãèŠçŽ ã®ã¹ã¿ã€ã«ãèšç®ããã®ã«å¿
èŠãªæéã®50ïŒ
以äžãã»ã¬ã¯ã¿ãŒã§æäœããæ®ãã®æéãã¹ã¿ã€ã«èªäœã®æ§ç¯ã«è²»ããããšã«ãªããŸãã
- ã¹ã¿ã€ã«ãèšç®ããèŠçŽ ã®æ°ãæžãããŸãã ã€ãŸããã¹ã¿ã€ã«ã®å€æŽãããŒãžå
šäœã§ã¯ãªããè€æ°ã®èŠçŽ ã«åããããŠããå Žåã®æ¹ãé©åã§ãã
ã¬ã€ã¢ãŠãã®æé©å
ããŒãžã¬ã€ã¢ãŠãã®åèšç®ã«ã¯ãæ·±å»ãªã·ã¹ãã ãªãœãŒã¹ãå¿ èŠã«ãªãå ŽåããããŸãã ãã®ããã»ã¹ãæé©åããã«ã¯ã次ã®ããšãèæ ®ããŠãã ããã
- ã¬ã€ã¢ãŠãã®åéèšã«ã€ãªããç¶æ³ã®æ°ãæžãããŸãã ã¹ã¿ã€ã«ãå€æŽãããšããã©ãŠã¶ã¯ãããã®å€æŽãåæ ããããã«ã¬ã€ã¢ãŠãã®åèšç®ãå¿
èŠãã©ããã確èªããŸãã èŠçŽ ã®å¹
ãé«ããäœçœ®ãªã©ã®ããããã£ã®å€æŽïŒäžè¬ã«ãèŠçŽ ã®å¹ŸäœåŠçç¹æ§ã«ã€ããŠè©±ããŠããïŒã«ã¯ãã¬ã€ã¢ãŠãã®å€æŽãå¿
èŠã§ãã ãããã£ãŠãã©ãããŠãå¿
èŠãªå Žåãé€ãããããã®ããããã£ãå€æŽããªãã§ãã ããã
- å¯èœãªéããå€ãã¬ã€ã¢ãŠãã¢ãã«ã®ä»£ããã«ãã¬ãã¯ã¹ããã¯ã¹ã¢ãã«ã䜿çšããŠãã ããã ãã®ã¢ãã«ã¯ä»ã®ã¢ãã«ãããé«éã§ãããããããã©ãŒãã³ã¹ã倧å¹
ã«åäžããŸãã
- ããã¥ã¡ã³ãã®äœæ¥ã¢ãã«ãé¿ããŠãèŠçŽ ã®ãã©ã¡ãŒã¿ãŒã®å®æçãªå€æŽãšãã®åŸã®èªã¿åããæäŸããŸãã JavaScriptã§ã¯ãåã®ãã¬ãŒã ã®DOMèŠçŽ ã®ãã©ã¡ãŒã¿ãŒïŒ
offsetHeight
ãoffsetWidth
ïŒã䜿çšã§ããŸãã ãããã®ãã©ã¡ãŒã¿ãŒãèªã¿åã£ãŠãåé¡ã¯çºçããŸããã ãã ãããã®ãããªãã©ã¡ãŒã¿ãŒãèªã¿åãåã«èŠçŽ ã®ã¹ã¿ã€ã«ãå€æŽããå ŽåïŒããšãã°ãäœããã®CSSã¯ã©ã¹ãåçã«è¿œå ããå ŽåïŒããã©ãŠã¶ãŒã¯ã¹ã¿ã€ã«ã®å€æŽãé©çšããã¬ã€ã¢ãŠããäœæããå¿ èŠãªããŒã¿ãããã°ã©ã ã«è¿ãããã«å€ãã®ãªãœãŒã¹ãè²»ããå¿ èŠããããŸãã ããã«ããããã°ã©ã ã®é床ãäœäžããå¯èœæ§ããããŸããå¯èœãªéããã®ãããªããšã¯é¿ããŠãã ããã
ã¬ã³ããªã³ã°ã®æé©å
å€ãã®å Žåããã®ã¿ã¹ã¯ã«æãæéãããããããããŒãžã®åæç»ã«ã€ãªããç¶æ³ãåé¿ããããšãéèŠã§ãã ããã§ã§ããããšã¯æ¬¡ã®ãšããã§ãã
- å€æãšéæ床ã®å€æŽãé€ããããããã£ãå€æŽãããšãåæç»ãè¡ãããŸãã ãããã®æ©èœã¯æ
éã«äœ¿çšããŠãã ããã
- ã¢ã¯ã·ã§ã³ãã¬ã€ã¢ãŠãã®åèšç®ãåŒãèµ·ãããå ŽåãèŠçŽ ã®å¹ŸäœåŠçãã©ã¡ãŒã¿ãŒã®å€æŽãèŠèŠçãªå€æŽã«ã€ãªãããããããŒãžãåæç»ããåŒã³åºãã«ã€ãªãããŸãã
- ã¬ã€ã€ãŒãšã¢ãã¡ãŒã·ã§ã³ã®ã¬ã€ã¢ãŠããã€ã³ããªãžã§ã³ãã«å¶åŸ¡ããããšã«ãããåæç»ãå¿
èŠãªããŒãžã®é åãæžãããŸãã
ãŸãšã
ãã®èšäºã§ã¯ãææ°ã®ãã©ãŠã¶ãŒã®ã¬ã³ããªã³ã°ãµãã·ã¹ãã ã«ã€ããŠèª¬æããŸããã ããŒãžã¬ã³ããªã³ã°ãžã®é©åãªã¢ãããŒãã¯ãWebã¢ããªã±ãŒã·ã§ã³ã®ããã©ãŒãã³ã¹ãšãŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ã®åäžã«ã€ãªãããŸãã
äžé£ã®èšäºã®åã®éšåïŒ
ããŒã1ïŒ JSã®ä»çµã¿ïŒãšã³ãžã³ãã©ã³ã¿ã€ã ã¡ã«ããºã ãã³ãŒã«ã¹ã¿ãã¯ã®æŠèŠ
ããŒã2ïŒ JSã®ä»çµã¿ïŒV8å éšãšã³ãŒãã®æé©åã«ã€ããŠ
ããŒã3ïŒ JSã®ä»çµã¿ïŒã¡ã¢ãªç®¡çã4çš®é¡ã®ã¡ã¢ãªãªãŒã¯ãããã³ããããšã®æŠã
ããŒã4ïŒ JSã®ä»çµã¿ïŒã€ãã³ãã«ãŒããéåæãããã³async / awaitã䜿çšããŠã³ãŒããæ¹åãã5ã€ã®æ¹æ³
ããŒã5ïŒ JSã®ä»çµã¿ïŒWebSocketãšHTTP / 2 + SSEã äœãéžã¶ïŒ
ããŒã6ïŒ JSã®ä»çµã¿ïŒWebAssemblyã®æ©èœãšç¯å²
ããŒã7ïŒ JSã®ä»çµã¿ïŒWeb Workersãš5ã€ã®äœ¿çšã·ããªãª
ããŒã8ïŒ JSã®ä»çµã¿ïŒãµãŒãã¹ã¯ãŒã«ãŒ
ããŒã9ïŒ JSã®ä»çµã¿ïŒWebããã·ã¥éç¥
ããŒã10ïŒ JSã®ä»çµã¿ïŒMutationObserverã䜿çšããŠDOMã®å€æŽã远跡ãã
芪æãªãèªè ïŒ Webãããžã§ã¯ãã®ããŒãžã®ã¬ã³ããªã³ã°ãæé©åããããã«ã©ã®ãããªãã¯ããã¯ã䜿çšããŠããŸããïŒ