ãã¹ãŠã®äººã«æšæ¶ïŒ
ãã®èšäºã¯ããã¶ã€ããŒã®éå¿çãªã¢ã€ãã¢ãå®çŸããããã«ãã©ãŠã¶ãŒã®ã¹ã¯ããŒã«ããŒãã«ã¹ã¿ãã€ãºããåé¡ã解決ããããšã«å°å¿µããŠããŸãã ãã®èšäºã¯ãhtmlãcssãjsãã¯ãããžãŒã«å ªèœãªäººã察象ãšããŠããŸãã ææ¡ããããœãªã¥ãŒã·ã§ã³ã¯ã劥åãã䜿çšã«åºã¥ããŠããŸãã
ãã®èšäºã§ã¯ã次ã®ã¿ã¹ã¯ãšç®æšã«ã€ããŠèª¬æãã解決ããŸãã
- èŠçŽ ã®ã¹ã¯ããŒã«ããã³ãµã€ãºå€æŽæã®æå°JavaScriptèšç®
- ã¯ãã¹ãã©ãŠã¶ãŒãšã¢ãã€ã«ãã©ãŠã¶ãŒã§ã®äœæ¥
- 䜿ãããããã«ã¹ã¿ãã€ãºãå®è£
- ã³ã³ãã³ããéžæããŠã¹ã¯ããŒã«ãããšãã®èŠçŽ ã®åäœãèæ ®ã«å ¥ãã
- ã³ã³ãã³ãã®æŽæ°ãå€æŽããŸãã¯èªã¿èŸŒã¿æã«ã¹ã¯ããŒã«ããŒã®ãã©ã¡ãŒã¿ãŒãæŽæ°ãã
- ãŠã£ã³ããŠã®å¹ ãå€æŽãããšãã®ãã©ãŠã¶ãŒã³ã³ãã³ãã®æšæºåäœã®ãã€ãã¹
ã€ã³ããã ã·ã¹ãã ã¹ã¯ããŒã«ã®æ©èœã
æ§ç¯ãããã®ãããããã«ãç°¡åãªäŸã瀺ããŸãïŒ äœæ¥ãåç § ïŒã
<div style="border: 3px solid #f08080; height: 300px; overflow: auto; width: 300px;"> <div style="background-color: #90ee90; border: 10px solid #4169e1; min-height: 600px; min-width: 600px;"> content... </div> </div>
ãã®é åã®ã³ã³ãã³ããããã²ãŒãããããã®ãã©ãŠã¶ã¯ã次ã®æ©èœãæäŸããŸãïŒãã¹ãŠãè©ŠããŠã¿ãããšããå§ãããŸãïŒã
- ããŠã¹ãã€ãŒã«ïŒäžéšã®ããŠã¹ã¯ãåçŽã¹ã¯ããŒã«ã«å ããŠãæ°Žå¹³ã«ã¹ã¯ããŒã«ããæ©èœãæäŸããŸãïŒ
- èŠçŽ ã«ãã©ãŒã«ã¹ãããç¢å°ããŒïŒäžãäžãå³ãå·ŠïŒ
- ã¿ãããããïŒMacintoshã³ã³ãã¥ãŒã¿ãŒã®ã¿ãããããã§ã¯ãç¹å¥ãªäŸ¿å©ããšã³ã³ãã³ãæäœã®ã¹ãªã«ãæããããšãã§ããŸãïŒ
- ã¿ãã¬ãããšé»è©±ã®ã¿ããã¹ã¯ãªãŒã³ãããã³ã³ã³ãã¥ãŒã¿ãŒ
- ãŸããã³ã³ãã³ããã¹ã¯ããŒã«ããŠåŒ·èª¿è¡šç€ºããããšãã§ããŸãïŒãã®æ©èœã¯ãããšãã°ãäžéšãèŠããªã倧ããªããã¹ãã匷調衚瀺ããããã«èšèšãããŠããŸãïŒ
- ãããŠãçŽæ¥ãã¹ã¯ããŒã«ããŒèŠçŽ ïŒã¹ã©ã€ããŒãšãã¿ã³
ã芧ã®ãšãããäžé£ã®æ©èœã¯éåžžã«å€§ãããéåžžã«é©åã«å®è£ ãããèãæããã䟿å©ã§ããšã³ããŠãŒã¶ãŒã«ãªãã¿ããããŸã...
jsããŒã«ã䜿çšããŠã¹ã¯ããŒã«ããŒã®å€èŠ³ãå€æŽããããšã¯ããã®ãã¹ãŠãŸãã¯äžéšãå®è£ ãã䟡å€ããããŸããïŒ
ã¯ã ïŒã³ã³ãã³ããããã²ãŒãããããjsã§å®éšããããªã©ã®æ°ããã¢ã€ãã¢ãããããã§ãã
no ïŒãã©ãŠã¶ã¯ãã§ã«ããããã¹ãŠãå®è¡ããŠããããã䜿çšæ¹æ³ãèŠã€ããå¿ èŠããããŸãã ããã¯ç§ã以äžã§è©±ãããšã§ãã
ã ããã
ãœãªã¥ãŒã·ã§ã³ã®HTMLæ§é ã¯æ¬¡ã®ãšããã§ãã
<div class="scrollar"> <div class="scrollar-viewport"> <div class="scrollar-systemscrolls"> <div class="scrollar-contentwrap"> <div class="scrollar-content"></div> </div> </div> </div> <div class="scrollar-scroll scrollar-vscroll"> <div class="scrollar-btn scrollar-btnup"></div> <div class="scrollar-btn scrollar-btndown"></div> <div class="scrollar-track scrollar-vtrack"> <div class="scrollar-thumb scrollar-vthumb"></div> </div> </div> <div class="scrollar-scroll scrollar-hscroll"> <div class="scrollar-btn scrollar-btnleft"></div> <div class="scrollar-btn scrollar-btnright"></div> <div class="scrollar-track scrollar-htrack"> <div class="scrollar-thumb scrollar-hthumb"></div> </div> </div> <div class="scrollar-corner"></div> </div>
Scrollarã¯ããœãªã¥ãŒã·ã§ã³ã®ååãšåå空éã§ãããåæã«ããœãªã¥ãŒã·ã§ã³ã䜿çšã§ããã©ã³ãã£ã³ã°ããŒãžäžã®ã¹ã¿ã€ã«ã®å ±ééšåãæé€ããŸãã
ããæ確ã«ããããã«ãæ§é ã説æããŸãã
- ã«ãŒããããã¯ã¯æ§é å šäœã®ã©ãããŒã§ãããæ§é å šäœã®é¢ç©ãšå¯žæ³ãå šäœãšããŠæ±ºå®ããŸãã
- ãã¥ãŒããŒã-ã³ã³ãã³ã衚瀺é åã¯ãã®ãããã¯ã«å¶éãããŠããŸãã
- systemscrolls-ãã®ãããã¯ã¯ã³ã³ãã³ãã®ã¹ã¯ããŒã«ãæ åœããŸãã
- contentwrapã¯ä¿®æ£ãããã¯ã§ãïŒãã®æå³ãšæ©èœã«ã€ããŠïŒã
- ã³ã³ãã³ã-ã³ã³ãã³ãèªäœã
- vtrackããã³htrack-åçŽããã³æ°Žå¹³ã¹ã¯ããŒã«ããŒã ãã®å 容ã«ããããã¹ãŠãæ確ã«ãªããŸãã
ä»ãããªãã¯ããŒãã€ã³ããæ€èšãå§ããããšãã§ããŸã...
äž»ãªè² æ ïŒã¹ã¯ããŒã«ããã³ãµã€ãºå€æŽæäœ
ç§ã®æèŠã§ã¯ããããã¯javascriptå®è£ ã§æããå°é£ãã§äžäŸ¿ãªæäœã§ãã ãªãã§ïŒ ããã°ã©ã ã§Resizeãå®è£ ããæ¯çãä¿æããã«ã¯ãåºæ¬çã«window.onresizeã€ãã³ããåŠçããå¿ èŠãããããã®ã€ãã³ãã®çºçäžã«ãããã€ãã®èŠçŽ ã®ãµã€ãºãšæ¯çã調æŽããå¿ èŠããããŸãïŒã»ãšãã©ã®å Žå...ïŒã ãã®æ¹æ³ã§ãµã€ãºãå€æŽããããšã®æ¬ ç¹ã¯ããã®ããã«ãããã°ããããšããèŠçŽ ã®ãµã€ãºãæ»ããã§ã¯ãªãããšã§ãïŒå°ããªäžè²«æ§ã®ãªããç®ã«èŠãããã¹ãããïŒ-ç§ãç解ããŸãã éãéçºã«æå ¥ããã€ã³ã¿ãŒãã§ã€ã¹å šäœãæ©èœãããããšãããšãããã¯ç®ã倧ããçããŸãã
ãããã£ãŠãèŠçŽ ã®ãµã€ãºãå€æŽãããšãã«æ倧ã®æ»ããããç¶æããã«ã¯ããããã¯èŠçŽ ã®ã©ããŒã¬ã€ã¢ãŠãã®ãªãã·ã§ã³ã®ããããã䜿çšããŠãäºãã«å¯ŸããŠçµ¶å¯Ÿé 眮ããç¹å®ã®åº§æšã«ãã€ã³ãããããšã§èŠçŽ ã®ãµã€ãºãå€æŽãã䟡å€ããããŸãïŒ
.scrollar, .scrollar-viewport, .scrollar-systemscrolls, .scrollar-contentwrap, .scrollar-content { bottom: 0px; height: auto; left: 0px; position: absolute; right: 0px; top: 0px; width: auto; } /* */ .scrollar { overflow: visible; position: relative; } /* */ .scrollar-contentwrap, .scrollar-content { bottom: auto; right: auto; }
ãã®ãããªã¹ã¿ã€ã«ã®çºè¡šåŸããã©ãŠã¶èªäœãã¹ã¯ããŒã«é åãšå éšèŠçŽ ã®äž¡æ¹ã®ãµã€ãºãå€æŽããŸãã 以äžã®èšäºã§ã¯ãããã€ãã®èŠçŽ ã®ã¹ã¿ã€ã«ãè£è¶³ããã³èª¿æŽããŠãæãŸããæè¯ã®çµæãéæããŸãã
Scrollã«ã€ããŠã ãã¹ã¯ããããã©ãŠã¶ãŒã§ã¹ã¯ããŒã«ãå®è£ ããã«ã¯ãããŠã¹ãã€ãŒã«ã€ãã³ããåŠçãããã®ã€ãã³ãããã®å€ãåæããå¿ èŠããããŸãïŒäžéšã®ããŠã¹ã§ã¯ã³ã³ãã³ããåçŽæ¹åã ãã§ãªãæ°Žå¹³æ¹åã«ã¹ã¯ããŒã«ã§ããããšãå¿ããªãã§ãã ããïŒãã¢ãã€ã«ãã©ãŠã¶ãŒã®å Žåã¯ãã¿ããã°ã«ãŒãã€ãã³ããåŠçããå¿ èŠããããŸãã ã€ãŸã ã¯ãã¹ãã©ãããã©ãŒã ãœãªã¥ãŒã·ã§ã³ã®å Žåãããã2ã€ã®å®è£ ãããã°ã©ã ããå¿ èŠããããŸãã ãã ãããã©ãŠã¶èªäœã«ã³ã³ãã³ãã¹ã¯ããŒã«ãé 眮ããããšããå§ãããŸãã systemscrollsèŠçŽ ã®ã¹ã¿ã€ã«ãå®çŸ©ããã ãã§ååã§ãïŒ
.scrollar-systemscrolls { overflow: scroll; }
ã·ã¹ãã ã¹ã¯ããŒã«ããŒãš22ãã¯ã»ã«ãé衚瀺ã«ãã
ã³ã³ãã³ããã¹ã¯ããŒã«ããã¿ã¹ã¯ã解決ããããã«ãoverflowïŒscrollããããã£ã䜿çšããŸãããããã«ããããã©ãŠã¶ãŒã«åžžã«ã¹ã¯ããŒã«ããŒã衚瀺ããããŠãŒã¶ãŒã«ã·ã¹ãã ã¹ã¯ããŒã«ã®ãã¹ãŠã®å©äŸ¿æ§ãæäŸãããŸãã ãã ãããããã®ã¹ã¯ããŒã«ããŒãé衚瀺ã«ããå¿ èŠããããŸãã ããã¯ããã¥ãŒããŒãã圹ç«ã€å Žæã§ã-ãã®ãããã¯ã¯ããã®éçãè¶ ãããã¹ãŠã®ãã®ãé ããŸãã ãããè¡ãã«ã¯2ã€ã®æ¹æ³ããããŸãã
.scrollar-viewport { overflow: scroll; } .scrollar-viewport { clip: rect(0, auto, auto, 0); clip: rect(0 100% 100% 0); }
ãªãŒããŒãããŒã䌎ãæåã®ãªãã·ã§ã³ã¯ç°¡åã«ç解ã§ããŸããããŠãŒã¶ãŒãã³ã³ãã³ããéžæããã«ãŒãœã«ãæ£ããæ¹åã«ãã©ãã°ãå§ãããšãã·ã¹ãã ã¹ã¯ããŒã«ããŒã衚瀺ãããå¯èœæ§ãé«ããªããŸãã ãã®ã¢ã¯ã·ã§ã³ã«ãããé衚瀺ã®é åã®äžããã¯ããŒã«ãããŸãã ã¯ãªãããªãã·ã§ã³ã¯ãã®åé¡ã®åœ±é¿ãåããŸãããããã®å Žåãie7ããµããŒãããããã«å°ããªããã¯ã䜿çšããå¿ èŠããããŸããã ããããããã ãã§ã¯ãããŸãã... Systemscrollsãããã¯ã¯ããã¥ãŒããŒããããã¯ãšåã寞æ³ã§ãã ã·ã¹ãã ã®ã¹ã¯ããŒã«ããŒã¯åŒãç¶ã衚瀺ãããŸãã ããã§ã¯ãããŒã¢ãŒã¡ã³ãã22pxãã䜿çšãããŸããããã¯ãsystemscrollsãããã¯ã調æŽããå€ã§ãã å®éãäžè¬çãªãã©ãŠã¶ã®ã¹ã¯ããŒã«ããŒã®åãã¯21pxæªæºã§ãã 調æŽèªäœã¯æ¬¡ã®ããã«ãªããŸãã
.scrollar-systemscrolls { bottom: -22px; right: -22px; }
ãã®åŸãã¹ã¯ããŒã«ããŒã¯é衚瀺ã«ãªããã¯ãªããã䜿çšããŠããªãã³ã°ãããé åã®å¢çãè¶ããŠé 眮ãããŸãã
ãããŠãçµæã¯äœã§ããïŒ ãã©ãŠã¶èªäœãèŠçŽ å šäœã®ãµã€ãºãå€æŽããã³ç£èŠããã³ã³ãã³ãã¯äžèšã®ãã¹ãŠã®æ¹æ³ã§ç°¡åãã€ã¹ã ãŒãºã«ã¹ã¯ããŒã«ããã·ã¹ãã ã®ã¹ã¯ããŒã«ããŒã¯é衚瀺ã«ãªããŸãã ãããããã®ãŸãŸã«ããŠãããšãå³äžã®ã³ã³ãã³ãã®äžéšã衚瀺ãããªããªããŸã...
ã³ã³ãã³ãã©ãããããã¯
contentwrapãããã¯ã®äž»ãªäž»ãªç®çã¯ããã¥ãŒããŒããããã¯ã§ã³ã³ãã³ããããã¯ãå®å šã«èŠãããšãã§ããããã«ããããšã§ãïŒç°ãªãã¹ã¯ããŒã«æ¹æ³ã§äžæ¹ã®ç«¯ããä»æ¹ã®ç«¯ãŸã§ã
ãã®æç¹ãŸã§ãjavascriptã¯å¿ èŠãããŸããã§ããããcontentwrapãããã¯ã®ãµã€ãºã調æŽããã®ã«åœ¹ç«ã¡ãŸãã
⊠var viewport = $(".scrollar-viewport", scrollar); var systemscrolls = $(".scrollar-systemscrolls", scrollar); var correct_h = systemscrolls[0].clientHeight - viewport.height(); // var correct_w = systemscrolls[0].clientWidth - viewport.width(); // âŠ
ãããã£ãŠãcontentwrapèŠçŽ ã®æ¬¡å ã¯ããããã®å€ãšã³ã³ãã³ããããã¯ã®ãµã€ãºã®å ç®ããååŸãããã³ã³ãã³ããããã¯ã®ãµã€ãºãå€æŽããããã³ã«ãããè¡ãå¿ èŠããããŸãã äŸå€ããããŸããã以äžã§èª¬æããŸãã
jsã§contentwrapãããã¯ã調æŽãããšããã©ãŠã¶ãŒã®å€èŠ³ãšããŒãžã§ã³ãããã³äœ¿çšããã¹ã¯ããŒã«ããŒã®å€ªããç¡èŠã§ããŸãã
Vscrollããã³hscrollãããã¯
vscrollãšhscrollã¯ã¹ã¯ããŒã«ããŒã§ãã çŸæç¹ã§ã®äž»ãªã¿ã¹ã¯ã¯ããããã端ã«ã貌ãä»ãããŠããã©ãŠã¶ãä»ããŠãµã€ãºãšåã®äœçœ®ãå€æŽãããããšã§ãã
.scrollar-scroll, .scrollar-track, .scrollar-btn, .scrollar-thumb, .scrollar-corner { position: absolute; } .scrollar-hscroll { bottom: 0px; height: 0px; left: 0px; right: 0px; } .scrollar-vscroll { bottom: 0px; right: 0px; top: 0px; width: 0px; } .scrollar-btnup { left: 0px; top: 0px; } .scrollar-btndown { bottom: 0px; left: 0px; } .scrollar-btnleft { left: 0px; top: 0px; } .scrollar-btnright { right: 0px; top: 0px; } .scrollar-vthumb { max-height: 100%; height: 30px; left: 0px; right: 0px; } .scrollar-hthumb { max-width: 100%; width: 30px; bottom: 0px; top: 0px; }
ãã®ãªã¹ãã«ã¯è€éãªãã®ã¯äœããªãã®ã§ãããã«èå³æ·±ãéšåã§ããã¹ã©ã€ããŒã«ç§»ããŸãã
ã©ã³ããŒ
ã©ã³ããŒæ©èœã®å®è£ ãæåãããã«ã¯ã次ã®ã¿ã¹ã¯ãèæ ®ããå¿ èŠããããŸãã
- äžèšã®æ¹æ³ã§ã³ã³ãã³ããã¹ã¯ããŒã«ãããšãã«ã¹ã©ã€ããŒã®äœçœ®ãå€æŽãã
- ã¹ã©ã€ããŒãããŠã¹ã§ãã©ãã°ãããããã®ã¢ã¯ã·ã§ã³ã«å¯Ÿããã³ã³ãã³ãã®åå¿
- ã³ã³ããŒãã³ãã®ãµã€ãºã«é¢é£ããŠã³ã³ãã³ãã®ãµã€ãºãå€æŽãããšãããŸãã¯ã³ã³ããŒãã³ãã®ãµã€ãºãå€æŽãããšããã¹ã©ã€ããŒã®äœçœ®ã®ãµã€ãºãå€æŽããŠç¶æããŸãïŒãã®ã¿ã¹ã¯ã¯ãã³ã³ããŒãã³ãå šäœã®ãã©ã¡ãŒã¿ãŒãæŽæ°ããããšã§è§£æ±ºããããœãªã¥ãŒã·ã§ã³ã«ã€ããŠã¯ä»¥äžã§èª¬æããŸãïŒ
ã³ã³ãã³ããã¹ã¯ããŒã«ãããšãã«ã¹ã©ã€ããŒã®äœçœ®ãå€æŽãã
ããã¯éåžžã«ç°¡åã§ãã systemscrollsãããã¯ã®set overflowïŒscrollããããã£ã«ããããã®ãããã¯ã§scrollã€ãã³ãããã£ããã§ãããã®ã€ãã³ããçºçããå Žåã§ããsystemsrollsãããã¯ã®å·Šäžç¹ãåºæºã«ããŠæ¯äŸä¿æ°ãèæ ®ããŠã³ã³ãã³ãã®äœçœ®ïŒscrollLeftããã³scrollTopããããã£ïŒã«å¿ããŠã¹ã©ã€ããŒã移åããŸãã³ã³ããŒãã³ãã®ãã©ã¡ãŒã¿ãŒãæŽæ°ããããã®é¢æ°ïŒè©³çŽ°ã¯ä»¥äžïŒã
ã¹ã©ã€ããŒããã©ãã°ã¢ã³ããããããã
ã¹ã©ã€ããŒã¯ãã·ã¹ãã å ã ãã§ãªããããŠã¹ãã€ã³ã¿ãŒã®åäœã«ãåå¿ããå¿ èŠããããŸãã ãããè¡ãã®ã¯é£ãããããŸããã ã¢ã«ãŽãªãºã ã¯æ¬¡ã®ãšããã§ãã
- ã©ã³ããŒã§mousedownã€ãã³ãããã£ããããŸã
- mousemoveããã³mouseupã€ãã³ããããã¥ã¡ã³ãèŠçŽ ã«æ¥ç¶ããŸã
- document.mousemoveã€ãã³ããåŠçããŠãã¹ã©ã€ããŒã®äœçœ®ãå€æŽããã³ã³ãã³ããã¹ã¯ããŒã«ããŸã
- document.mouseupã€ãã³ãããã£ãããã-ããã¥ã¡ã³ãèŠçŽ ã§mousemoveããã³mouseupã€ãã³ããç¡å¹ã«ããŸã
ã芧ã®ãšãããã¢ã«ãŽãªãºã ã¯éåžžã«åçŽã§ããã1ã€ã®æ³šæç¹ããããŸããã¹ã©ã€ããŒã®äœçœ®ãå€æŽãããããæ£ç¢ºã«ã¯ããã®äœçœ®ãå€æŽããã¢ã«ãŽãªãºã ã§ãã ã¹ã©ã€ããŒã®äœçœ®ã¯ã次ã®2ã€ã®æ¹æ³ã§å€æŽã§ããŸãã
- systemscrollsèŠçŽ ããã®ã¹ã¯ããŒã«ã€ãã³ãã 次ã®ããã«çºçããŸããjsã䜿çšããŠã³ã³ãã³ããã¹ã¯ããŒã«ããã«ã¯ãsystemscrollsãããã¯ã®scrollLeftããããã£ãšscrollTopããããã£ãå€æŽããå¿ èŠããããŸãããããã®ããããã£ãå€æŽãããšããã®ããã°ã§ã¹ã¯ããŒã«ã€ãã³ããã¹ããŒãããŸãã ãããã£ãŠãäžèšã®ã³ã³ãã³ããã¹ã¯ããŒã«ãããšãã«ã¹ã©ã€ããŒã®äœçœ®ãå€æŽããã¢ã«ãŽãªãºã ãæ©èœããŸãã
- ã¹ã©ã€ããŒã®mousedownã€ãã³ãããã£ãããããããsystemscrollsèŠçŽ ã®scrollã€ãã³ãã®åŠçãç¡å¹ã«ããsystemsrollsãããã¯ã®scrollLeftããããã£ãšscrollTopããããã£ãå€æŽããŠãã³ã³ãã³ããã¹ã¯ããŒã«ããªããããã¥ã¡ã³ãèŠçŽ ã®mousemoveã€ãã³ãã®ã¹ã©ã€ããŒèŠçŽ ã移åããå¿ èŠããããŸãã
äžèŠãæåã®æ¹æ³ã®æ¹ãè¯ãããã§ãã å®è£ ã«å¿ èŠãªåŽåãå°ãªããªããŸãã ãã ãããã®æ¹æ³ã®æ¬ ç¹ã¯ãsystemsrolls.scrollã€ãã³ããä»ããçŸåšã®ãã£ãŒãããã¯ã§ãïŒå³ãåç §ïŒãããã«ãããããŠã¹ãã€ã³ã¿ãŒããã°ãã移åãããšãã¹ã©ã€ããŒãããŠã¹ãã€ã³ã¿ãŒããèããé ãå§ããããã«ãªããŸãã ãã®å Žåãsystemscrollsãããã¯ã®scrollLeftããããã£ãšscrollTopããããã£ãå€æŽããããã³ã«systemscrolls.scrollã€ãã³ããçºçããé¢æ°ãåŒã³åºããŠã¹ã©ã€ããŒã移åããŸãã
2çªç®ã®æ¹æ³ã䜿çšãããšãããè¯ãçµæãåŸãããšãã§ããŸãã systemscrolls.scrollã€ãã³ãã®ãã¿ããããã³ã¢ã¿ããã«é¢ããè¿œå ã®æäœã¯ãããã¥ã¡ã³ãèŠçŽ ã®mousemoveããã³mouseupïŒããããïŒã€ãã³ãã§2åã®ã¿çºçããŸãã ãããã£ãŠãdocument.mousemoveã€ãã³ãã®åŠçã¯ããéããããæé©ã§ãïŒå³ãåç §ïŒã
ã³ã³ããŒãã³ãèšå®ã®æŽæ°
ãã®ãããéåžžã«éèŠãªæ©èœãã€ãŸãã³ã³ããŒãã³ãã®ãã©ã¡ãŒã¿ã®æŽæ°ãå¿ èŠã«ãªããŸããã ãã®æ©èœã§ã¯ã次ã®ããã«å®è¡é床ã確ä¿ããå¿ èŠããããŸãã ã³ã³ãã³ãã®ãµã€ãºå€æŽãå€æŽæã«é »ç¹ã«åŒã³åºãããšãã§ãããããã»ãšãã©ã¯çŽç²ãªjsã§æžãããŠããŸãã 以äžã¯ããã©ã¡ãŒã¿ãŒãæ°Žå¹³æ¹åã«æŽæ°ããã³ãŒãã§ãã
// if (options.hscroll) { scroll = env.hscroll; var ss_cw = ss.clientWidth; // contentwrap cw.style.width = (ct.offsetWidth + env.correct_w) + "px"; while (Math.abs(cw.scrollWidth - ct.offsetWidth) <= 1) { cw.style.width = (ct.offsetWidth + 1000) + "px"; cw.style.width = (ct.offsetWidth + env.correct_w) + "px"; } var ss_sw = ss.scrollWidth; // var htrack_w = scroll.track.width(); var hthumb_w = htrack_w * ss_cw / ss_sw; if (hthumb_w > htrack_w) { hthumb_w = htrack_w; } else if (hthumb_w < 30) { hthumb_w = 30; } scroll.thumb.outerWidth(hthumb_w); // x = htrack_w - hthumb_w; scroll.ratio = (ss_sw - ss_cw) / (x < 1 ? 1 : x); if (scroll.ratio < 1) scroll.ratio = 1; // scroll.min_pos = 0; scroll.max_pos = htrack_w - hthumb_w; // scroll.thumb.css("left", ss.scrollLeft / scroll.ratio); }
ãã®ãªã¹ãããããã³ã³ãã³ãã©ããã®å¹ ã調æŽãããã³ãŒãã«æ³šæãæããããšæããŸããæ®ãã¯èª¬æãªãã§æ確ã§ãã ãã®äœåã®æå³ã¯æ¬¡ã®ãšããã§ãã
- ãã©ãŠã¶ãŒã§ã¯ãã³ã³ãã³ãã®åçŽæ¹åãžã®å±éãæ°Žå¹³æ¹åãããåªå ãããŸããã€ãŸãããã©ãŠã¶ãŒãŠã£ã³ããŠã®å¹ ãå€æŽãããšïŒã³ã³ãã³ãã®å¹ ã«å³å¯ãªå¶éããªãå ŽåïŒãã³ã³ãã³ãã®é«ããå¶éãªãã«å¢å ããå¹ ãæžå°ããŸãã å®éããã¹ãŠãè«ççã§ãŠãŒã¶ãŒãã¬ã³ããªãŒã§ãããªããªãã ãã©ãŠã¶ãŠã£ã³ããŠã«åçŽã¹ã¯ããŒã«ãšåæã«æ°Žå¹³ã¹ã¯ããŒã«ãååšããããšã¯äžäŸ¿ã§ããã³ã³ãã³ããåçŽã«åŒã£åŒµãæ¹ãè¯ãã§ãããã ããããã€ã³ã¿ãŒãã§ã€ã¹èŠçŽ ã®ã¹ã¯ããŒã«é åã«é¢ããŠã¯ãå¿ èŠã«å¿ããŠæ°Žå¹³ã¹ã¯ããŒã«é åãèªåçã«å¢å ããããã«ããŸãã ãã®5è¡ã®ã³ãŒãã¯ãã®åé¡ã解決ããŸãããã©ãŠã¶ãŒãèŠçŽ ãæ°Žå¹³æ¹åã«äžŠã¹ãããšãã§ãããã©ãããå€æããã³ã³ãã³ããç®çã®ãµã€ãºã«æ¡åŒµããŸãã
ã³ã³ããŒãã³ãã®èšå®ãæŽæ°ããå¿ èŠãããã®ã¯ãã€ã§ããïŒ
- åæå
- ãã©ãŠã¶ãŠã£ã³ããŠã®ãµã€ãºãå€æŽãã
- å 容ã®å€æŽ
æåã®2ã€ã®ã±ãŒã¹ãéåžžã«éæã§ããå ŽåãæåŸã®ã±ãŒã¹ã«ã¯èœãšãç©ŽããããããããŸãã ã³ã³ãã³ãã¯ãèŠçŽ ã®åé€ãŸãã¯è¿œå äžã ãã§ãªãããµã€ãºãäºåã«èšå®ãããŠããªãå Žåãªã©ãäžéšã®åçã®ããŒãã®å®äºæã«ãå€æŽãããå¯èœæ§ããããŸãã ãã¹ãŠã®onloadã€ãã³ããªãã·ã§ã³ããã£ããã§ããŸãããããã ãã®äŸ¡å€ã¯ãããŸããã æé©ãªãœãªã¥ãŒã·ã§ã³ã¯setIntervalïŒæŽæ°ã300ïŒã§ããæŽæ°æ©èœã¯300ããªç§ããšã«èµ·åããããã©ãŠã¶ã«ã»ãšãã©è² è·ãããããããã¹ãŠãéåžžã«ä¿¡é Œã§ããŸãã
ã«ã¹ã¿ãã€ãº
ã«ã¹ã¿ãã€ãºã¯ããããã¹ãŠã§ãããã®ã§ãã ç®æšã¯ãã³ãŒããŒã®åŽåãæå°éã«æããæéãç¯çŽããããšã§ããã ã¹ã¯ããŒã«ããŒã®èŠçŽ ã®æ§é ã«é¢ããããã€ãã®å®éšã®åŸã以äžã®æ§é ã¯ããæè»ã§ãã
<div class="scrollar-scroll scrollar-vscroll"> <div class="scrollar-btn scrollar-btnup"></div> <div class="scrollar-btn scrollar-btndown"></div> <div class="scrollar-track scrollar-vtrack"> <div class="scrollar-thumb scrollar-vthumb"></div> </div> </div>
ãã®ã¬ã€ã¢ãŠãã¯åçŽã¹ã¯ããŒã«ããŒã§ãïŒæ°Žå¹³ã®å Žåã¯ãã¹ãŠåãã§ãïŒã ãã®ãããªæ§é ã®å©ç¹ã¯æ¬¡ã®ãšããã§ãã
- æ±çšã¯ã©ã¹scrollar-scrollãscrollar-btnãscrollar-trackãscrollar-thumbã䜿çšãããšãåçŽã¹ã¯ããŒã«ããŒãšæ°Žå¹³ã¹ã¯ããŒã«ããŒã®äž¡æ¹ã«å ±éã®ã¹ã¿ã€ã«ãèšå®ã§ããŸãïŒããšãã°ãscrollar-btn {displayïŒnone;}ãèšå®ããŠããã¿ã³ãé衚瀺ã«ã§ããŸãïŒã
- scrollar-btnããã³scrollar-trackã¯ã芪èŠçŽ scrollar-scrollã«é¢é£ããŠåºå®ãããŠããŸããããã«ããããã©ãŠã¶ã«ãããscrollar-scrollã®ãµã€ãºãšåæ§ã«ããããã®äœçœ®ãšãµã€ãºãå€æŽã§ããŸãã
- scrollar-trackèŠçŽ ã¯ãã¹ã¿ã€ãªã³ã°ãå¿ èŠãšããŸããã scrollar-thumbã¹ã©ã€ããŒã®ç§»åç¯å²ã決å®ããããã«èšèšãããŠããŸãããå¿ èŠã«å¿ããŠãã®èŠçŽ ã«ã¹ã¿ã€ã«ãé©çšããããšãã§ããŸãã
- èŠçŽ ã¯scrollar-scrollã«å¯ŸããŠçµ¶å¯ŸïŒäœçœ®ïŒçµ¶å¯ŸïŒã«é 眮ãããŸããããã«ãããèŠçŽ ãçžäºã«éåžžã«ç°¡åã«é 眮ã§ããŸãã
å®éããã¹ãŠã®ã«ã¹ã¿ãã€ãºã¯ã¹ã¿ã€ã«ã®èšè¿°ã«åž°çããŸãã èšäºã®æåŸã«ãã«ã¹ã¿ãã€ãºã®äŸãžã®ãªã³ã¯ãšããããã®äŸã®ã¹ã¿ã€ã«ãã¡ã€ã«ãžã®ãªã³ã¯ãèšèŒãããŠããŸãã
ãããŠãæ°Žå¹³ãŸãã¯åçŽã¹ã¯ããŒã«ãå¿ èŠãªãå Žåã¯ã©ããªããŸããïŒ
ç°¡åã§ããã³ã³ããŒãã³ããåæåãããšãã«ãå¿ èŠã®ãªãã¹ã¯ããŒã«ãæå®ããå¿ èŠããããŸãïŒããã©ã«ãã§ã¯äž¡æ¹ã衚瀺ãããŸãïŒã å¯èŠæ§ãšã¹ã¯ããŒã«ã管çããã«ã¯ãã¯ã©ã¹ãè¿œå ãŸãã¯åé€ããŸãã ãŸãããããã®ã¯ã©ã¹ãè¿œå ãããšãã³ã³ãã³ãã®ãµã€ãºã«åœ±é¿ããŸãïŒããšãã°ãhscrollïŒfalseã䜿çšãããšããã€ãã£ããã©ãŠã¶ãŒã®æ©èœã«ããã³ã³ãã³ãã®å¹ ãèªåçã«å€æŽãããŸãïŒ
ã³ã³ãã³ããå€æŽããã«ã¯ïŒ
ã³ã³ãã³ãé¢æ°ïŒãã¢ã¯ã·ã§ã³ããã³ã³ãã³ãïŒããããŸããã¢ã¯ã·ã§ã³ã¯jQueryã³ã³ãã³ã管çé¢æ°ïŒããã¹ããhtmlãè¿œå ãè¿œå ...ïŒã§ãã ãã©ã¡ãŒã¿ãŒãªãã§ãã®é¢æ°ãåŒã³åºãããšãã§ããŸãããã®åŸãjQueryãªããžã§ã¯ããè¿ããæäœã§ããŸãããã®å Žåãã³ã³ããŒãã³ãã®ãã©ã¡ãŒã¿ãŒã¯300ããªç§ããšã«æŽæ°ãããŸãã äŸïŒ
- ã³ã³ãã³ãïŒ "html"ã "Abcd"ïŒ-ã¹ã¯ããŒã«é åã®ã³ã³ãã³ããããã¹ãä»ãã®æ®µèœã«çœ®ãæããŸããã³ã³ããŒãã³ãã®ãã©ã¡ãŒã¿ãŒã®æŽæ°ã¯ãæ©èœãå®äºããçŽåŸã«å³åº§ã«è¡ãããŸãã
- contentïŒïŒãhtmlïŒ "Abcd"ïŒ-å¹æã¯åã®äŸãšåãã§ãããsetIntervalã«ãã£ãŠã³ã³ãã³ããæŽæ°ãããŸãã極端ãªå ŽåãupdateïŒïŒé¢æ°ã匷å¶çã«åŒã³åºãããšãã§ããŸã
èšäºãžã®ãªã³ã¯ïŒ
ã«ã¹ã¿ãã€ãº -ãã®ããŒãžã«ã¯ãã«ã¹ã¿ãã€ãºã®ããã®ããã€ãã®ãªãã·ã§ã³ã衚瀺ãããŸãããŸãããã©ãŠã¶ãŠã£ã³ããŠã®ãµã€ãºãå€æŽããããã®ã¹ã¯ããŒã«èŠçŽ ã®åå¿ããã¹ãããããšãã§ããŸãã
GitHub-èšäºã§èª¬æãããŠãããã¹ãŠãèŠã€ããããšãã§ãããªããžããª
ããã©ã«ãã¹ã¿ã€ã« -ã«ã¹ã¿ã ã¹ã¿ã€ã«ã®äŸ
Safariã¹ã¿ã€ã« -Mac OS 10.8ã®ã¹ã¿ã€ã«ã§ã®ã¹ã¯ããŒã«ããŒã®æ§åŒ
ãããã«
äœãæ°ãããã®ãçºæãã䟡å€ã¯ãããŸããïŒ ãã¡ããïŒ æ°ããã¢ã€ãã¢ã¯ãããããæªæ¥ã«åœ±é¿ãäžããå¯èœæ§ããããŸãïŒç¹å®ã®å Žå-ãŠãŒã¶ããªãã£ã®æªæ¥ïŒ