<分区>
标签 javascript jquery html css
<分区>
假设我有一个可滚动的 div。
<div style="width:300px;height:150px;overflow:scroll;">
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
I WANT TO BE TOP OF THE SCROLLABLE DIV,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
</div>
div 将从顶部的第一个“hi,
”开始显示。现在这只是一个例子,我的可滚动 div 包含的内容比这个例子多得多。
我希望能够以某种方式将焦点放在 div 中显示的特定内容区域。因此,在这个示例中,滚动条已经向下滚动了一点,其中“I WANT TO BE TOP OF THE SCROLLABLE DIV
”显示在顶部。如何
最佳答案
您可以使用标签使用纯 html 来完成..
<a href="#scroll">click</a>
<div style="width:300px;height:150px;overflow:scroll;">
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
<span id="scroll">I WANT TO BE TOP OF THE SCROLLABLE DIV,</span><br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
hi,<br />
</div>
关于javascript - 如何专注于可滚动 div 的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46427083/