获取滚动条位置

在进行页面刷新时  刚开始使用ajax局部熟悉  但因为他需要在js中拼接的代码太长,后期改动不方便,且样式调整也不方便,
因为种种不方便采用form提交全页面刷新,
全部刷新时页面滚动条会回复到最顶端,在将使得界面用户体验不好。
因此在页面提交之前,记录滚动条的位置

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 };
    }

猜你喜欢

转载自15757126299.iteye.com/blog/2270050
今日推荐