js 怎么兼容性获取滚动条总高度和已经滚动到得位置,这个是个难题,然后用总高度乘70%

这个是兼容的  我公司的项目就用的这个获取的。
 function  ScollPostion() {//滚动条位置
        var t, l, w, h;
        if (document.documentElement && document.documentElement.scrollTop) {
            t = document.documentElement.scrollTop;
            l = document.documentElement.scrollLeft;
            w = document.documentElement.scrollWidth;
            h = document.documentElement.scrollHeight;
        } else if (document.body) {
            t = document.body.scrollTop;
            l = document.body.scrollLeft;
            w = document.body.scrollWidth;
            h = document.body.scrollHeight;
        }
        return { top: t, left: l,  w, height: h };
    }

追问

得出来的结果都有点问题!不是很精确啊!
 

回答

是吗  我们都用了很久了
 

追问

我用top/height>0.7
结果top=220,height=950
我都拉到底了啊
你把具体代码给我吧!我估计我代码是不是有问题!
 

回答

var h =document.body.clientHeight;  //页面高度
var c = scollPostion().top; //滚动条top
 var wh = $(window).height(); //页面可是区域高度
 var s = h - (c + wh);
 if (  s/h>0.7   ) {
    //  loadings(); // 试试
 }
 

追问

请教下,怎么获取DIV的BLUR事件,这个事件在INPUT下可以,但是在DIV下无法执行,怎么处理???要代码!
 

回答

我没用过DIV的BLUR事件  不知道能不能用  
  抱歉






$(div).scroll(function(){
       if($(this).attr('scrollTop')/$(this).height() > 0.7){
              // loading();
       }
}); 
原文地址:https://www.cnblogs.com/ymj0906/p/2567314.html