js动态监测滚动条的位置

浏览755
    $(window).scroll(function(){
	 console.log(ScollPostion())
     })
	   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,
		        width: w,
		        height: h
		    };
		}

  • 暂无任何回答