How to get the scroll position value of a document?
相关问题
- 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
You can try this for example, this code put the scrollbar at the bottom for all DIV tags
Remember: jQuery can accept a function instead the value as argument. "this" is the object treated by jQuery, the function returns the scrollHeight property of the current DIV "this" and do it for all DIV in the document.
It uses HTML DOM Elements, but not jQuery selector. It can be used like:
Here's how to get the
scrollHeight
of an element obtained using a jQuery selector:If
selector
is the id of the element (e.g.elemId
), it is guaranteed that the 0-indexed item of the array will be the element you wish to select, andscrollHeight
will be correct.To get the actual scrollable height of the areas scrolled by the window scrollbar, I used
$('body').prop('scrollHeight')
. This seems to be the simplest working solution, but I haven't checked extensively for compatibility. Emanuele Del Grande notes on another solution that this probably won't work for IE below 8.Most of the other solutions work fine for scrollable elements, but this works for the whole window. Notably, I had the same issue as Michael for Ankit's solution, namely, that
$(document).prop('scrollHeight')
is returningundefined
.Something like this should solve your problem:
Ps: Call that function every time you need it, the alert is for testing purposes..