var $sg=function(id){return document.getElementById(id)};
var obj3=$sg("container3");
var top = document.body.scrollTop||document.documentElement.scrollTop;
alert(top);
alert(document.documentElement.clientHeight);
alert(window.innerHeight);
scrollTop高度只作用于body元素,主要代表滚动条滚动的高度。
有效屏幕高度为当前浏览器屏幕的可视高度
可以通过
document.documentElement.clientHeight
window.innerHeight
取得,结合这两个方法可以实现多个效果,最有代表性的就是首屏优化策略以及图片资源的延迟加载