How do I get the scroll position of a document?

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

How to get the scroll position value of a document?

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 21:40

    Something like this should solve your problem:

    $.getDocHeight = function(){
         var D = document;
         return Math.max(Math.max(D.body.scrollHeight,    D.documentElement.scrollHeight), Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), Math.max(D.body.clientHeight, D.documentElement.clientHeight));
    };
    
    alert( $.getDocHeight() );
    

    Ps: Call that function every time you need it, the alert is for testing purposes..

提交回复
热议问题