How do I use jquery to scroll right down to the bottom of an iframe or page?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
A simple function that jumps (instantly scrolls) to the bottom of the whole page. It uses the built-in
.scrollTop()
. I haven’t tried to adapt this to work with individual page elements.If you don't care about animation, then you don't have to get the height of the element. At least in all the browsers I've tried, if you give
scrollTop
a number that's bigger than the maximum, it'll just scroll to the bottom. So give it the biggest number possible:If you want to scroll the page, rather than some element with a scrollbar, just make
myScrollingElement
equal to 'body, html'.Since I need to do this in several places, I've written a quick and dirty jQuery function to make it more convenient, like this:
So I can do this when I append a buncho' stuff:
scrollTop() returns the number of pixels that are hidden from view from the scrollable area, so giving it:
will actually overshoot the bottom of the page. For the scroll to actually 'stop' at the bottom of the page, the current height of the browser window needs subtracting. This will allow the use of easing if required, so it becomes:
This one worked for me:
The scripts mentioned in previous answers, like:
or
$(window).scrollTop($(document).height());
will not work in Chrome and will be jumpy in Safari in case
html
tag in CSS hasoverflow: auto;
property set. It took me nearly an hour to figure out.For example: