$(document).scrollTop(); $(document).scrollLeft();js获取滚动距离有点麻烦,要考虑兼容性:
/** * 获取滚动条距离顶端的距离 * @return {}支持IE6 */ function getScrollTop() { var scrollPos; if (window.pageYOffset) { scrollPos = window.pageYOffset; }else if (document.compatMode && document.compatMode != 'BackCompat'){ scrollPos = document.documentElement.scrollTop; }else if (document.body) { scrollPos = document.body.scrollTop; } return scrollPos; }