→mdn
ナビゲーションや CSSOM のスクローリング API によってスクロールするボックスにスクロールが発生した際の、そのスクロールの振る舞いを設定します。
名前 | scroll-behavior
|
---|---|
値 | auto | smooth |
初期値 | auto |
適用対象 | スクロールするボックス |
継承 | なし |
百分率 | |
算出値 | 指定通り |
正準的順序 | |
アニメーション型 | 離散値 |
auto
<DIV style="border:1px solid red; width:100px; height:100px; scroll-behavior:auto; overflow:auto; "> <SPAN id=AA style="line-height:100px; border:1px solid black;">A</SPAN><BR> <SPAN id=AB style="line-height:100px; border:1px solid black;">B</SPAN><BR> <SPAN id=AC style="line-height:100px; border:1px solid black;">C</SPAN><BR> </DIV> <A href="#AA">A</A> <A href="#AB">B</A> <A href="#AC">C</A>
smooth
<DIV style="border:1px solid red; width:100px; height:100px; scroll-behavior:smooth; overflow:auto; "> <SPAN id=AsmoothA style="line-height:100px; border:1px solid black;">A</SPAN><BR> <SPAN id=AsmoothB style="line-height:100px; border:1px solid black;">B</SPAN><BR> <SPAN id=AsmoothC style="line-height:100px; border:1px solid black;">C</SPAN><BR> </DIV> <A href="#AsmoothA">A</A> <A href="#AsmoothB">B</A> <A href="#AsmoothC">C</A>
HTML:
<nav> <a href="#page-1">1</a> <a href="#page-2">2</a> <a href="#page-3">3</a> </nav> <div class="scroll-container"> <div class="scroll-page" id="page-1">1</div> <div class="scroll-page" id="page-2">2</div> <div class="scroll-page" id="page-3">3</div> </div>
CSS:
a { display: inline-block; width: 50px; text-decoration: none; } nav, .scroll-container { display: block; margin: 0 auto; text-align: center; } nav { width: 339px; padding: 5px; border: 1px solid black; } .scroll-container { width: 350px; height: 200px; overflow-y: scroll; scroll-behavior: smooth; } .scroll-page { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 5em; }
表示内容: |
表示内容: |