[英]How to scroll on click of a button to a certain element/div on the bottom of the page with jQuery?
[英]How to scroll with jQuery (Bottom of element should be at the bottom of the page)
在我的 HTML 頁面上,我有可以通過按鈕動態添加的內容。 當添加的東西不再在視口中時,我想滾動以將其放入視口。 由於添加的內容始終添加在添加內容的可點擊按鈕下方,因此我總是希望元素的底部在滾動后位於視口的底部,但我只能將元素的頂部放在帶有 function 的視口頂部:
if (!elementInViewport(document.getElementById("ElementId"))){
$([document.documentElement, document.body]).animate({
scrollTop: $("#ElementId").offset().top
}, 2000);
}
沒有scrollBottom
而不是scrollTop
,當我用offset().bottom
替換offset().top
時,function 根本不做任何事情。
我怎樣才能做到這一點?
試試scrollIntoView()
function:
if (!elementInViewport(document.getElementById("ElementId"))){
document.getElementById("ElementId").scrollIntoView(false);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.