1
私はを使用しています。スクロールは機能していますが、同時に私のページ全体のレイアウトが崩れます。デモ以下の通りです:Element.scrollIntoView()の振る舞い動作
* {
margin: 0;
padding: 0;
}
html, body {
width: 100%;
height: 100%;
}
.content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
background-color: lightgray;
}
ul {
position: absolute;
width: 100%;
height: 300px;
left: 0;
bottom: 0;
background-color: gray;
overflow-y: scroll;
}
li {
list-style: none;
}
#div {
position: absolute;
width: 100%;
height: 300px;
left: 0;
bottom: -300px;
background-color: darkgray;
}
button {
position: absolute;
right: 0;
bottom: 0;
}
<div class=content>
<!-- it's the ul to scroll, staying at the bottom of the page -->
<ul>
<li id=li>abc</li>
<li>def</li>
</ul>
<!-- it's the div hidden under the bottom edge of the page -->
<div id=div>i should stay hidden.</div>
<button onclick=li.scrollIntoView();>scrollIntoView</button>
</div>
私は、ページの下部エッジの下<div>
を非表示にします。 scrollIntoView
第1 <li>
が<ul>
である場合、隠された<div>
が引き出されます。 <div>
だけでなく、ページの全内容が300pxにプルアップされています。
<li>
を<ul>
に単純にスクロールすることが期待されます。ページ全体のレイアウトに影響するのはなぜですか?