封装scroll()
function scroll(){ if(window.pageYOffset !== undefined){ return { "top": window.pageYOffset, "left": window.pageXOffset }; }else if(document.compatMode === "CSS1Compat"){ return { "top": document.documentElement.scrollTop, "left": document.documentElement.scrollLeft }; }else{ return { "top": document.body.scrollTop, "left": document.body.scrollLeft }; } }
scroll().top 代表scrollTop
scroll().left 代表scrollLeft
或者:
var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;