How do I get the scroll position of a document?

前端 未结 9 1744
面向向阳花
面向向阳花 2020-12-12 20:53

How to get the scroll position value of a document?

9条回答
  •  抹茶落季
    2020-12-12 21:28

    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 returning undefined.

提交回复
热议问题