我有一个带有溢出隐藏属性的 div,我希望当我的页面加载时滚动位置在底部。
我有这个:
我在加载页面时想要这个:
有什么想法吗?
最佳答案
这可以通过这种方法轻松完成....
function setItem(){
// We go through all items and change the value of the id attribute to empty
$('#mylist li').each(function (i, v) {
$(v).attr('id', '');
});
// We add the items
$('#mylist').append('<li id="last">test</li>');
// Currently there is only one identifier called "last"
window.location.href = '#last';
}
#mylist{
overflow-y: scroll;
height: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="setItem();">Add</button>
<div id="mylist"></div>
只需创建新的 li 并将其 id 修改为 last 并将文档 hrefing 为 last。 然后从所有 li 中删除 id 属性。 这里 li 是消息。
关于html - 如何在页面加载时在底部设置垂直滚动处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57903643/