JS按高度滚动页面到位置

JS scroll page to location by height

本文关键字:位置 滚动 高度 JS      更新时间:2023-09-26

我有一个div,可以动态增加大小。在页面顶部,我有"添加注释"按钮。当我按"添加注释"时,我想将页面滚动到页面底部(出现此新注释的位置)。这是 SharePoint 上的.aspx页面。

目前我有这种解决方案,这不起作用,为什么:

<a ng-click="AddNote()" onclick="GetMeetingsHeight()" href="#">Add note</a> <%-- Adds new note --%>
function GetMeetingsHeight() {
            var winHeight = $('.detailsdiv').height(); // It works, when I ask by class
            document.getElementById("winHei").innerHTML = winHeight;
            window.scrollTo(0, winHeight);
        }

试试这个

 var sc = $('.detailsdiv').offset().top;
 $('body,html').animate({
     scrollTop: sc
  },'slow');

由于以前的解决方案存在某种奇怪的问题,因此我将它们混合在一起并使其正常工作。

在底部,我添加了div,如下所示<div id="footer"></div>

function GoToBottom() {
            var redir = document.URL;
            if (redir.indexOf("#footer") == -1)
                redir += "#footer";
            window.location.assign(redir);
        };