html - 如何在页面加载时在底部设置垂直滚动处理程序

标签 html css scroll

我有一个带有溢出隐藏属性的 div,我希望当我的页面加载时滚动位置在底部。

我有这个:

1

我在加载页面时想要这个:

2

有什么想法吗?

最佳答案

这可以通过这种方法轻松完成....

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/

相关文章:

html - CSS 圆 Angular 框的 "padding-bottom: 1px;"是什么?

javascript - 使用 Javascript 滚动时导航栏淡入淡出动画

没有用户交互和编程滚动的 iOS UIScrollView

javascript - 使用表单中的按钮而不提交表单 jsp

CSS :hover Within an 'absolute' Positioned Element

html - 左对齐 CSS 下拉菜单

html - 我怎样才能使这个字体变小而不弄乱它的效果

jquery - CSS 叠加效果未关闭

javascript - 如何将 HTML 页面中包含的变量传递给 PHP,然后用 JS 显示 - Chart.js

html - 不使用 img 元素的 css 背景图像回调