jQuery Scroll to bottom of page/iframe

2019-01-02 17:17发布

How do I use jquery to scroll right down to the bottom of an iframe or page?

8条回答
无色无味的生活
2楼-- · 2019-01-02 17:49

After this thread didn't work out for me for my specific need (scrolling inside a particular element, in my case a textarea) I found this out in the great beyond, which could prove helpful to someone else reading this discussion:

Alternative on planetcloud

Since I already had a cached version of my jQuery object (the myPanel in the code below is the jQuery object), the code I added to my event handler was simply this:

myPanel.scrollTop(myPanel[0].scrollHeight - myPanel.height());

(thanks Ben)

查看更多
余欢
3楼-- · 2019-01-02 17:57

If you want a nice slow animation scroll, for any anchor with href="#bottom" this will scroll you to the bottom:

$("a[href='#bottom']").click(function() {
  $("html, body").animate({ scrollTop: $(document).height() }, "slow");
  return false;
});

Feel free to change the selector.

Edit: Please look at the answer below by Tom Bates for a potentially better answer.

查看更多
登录 后发表回答