Skip to content

Latest commit

 

History

History
25 lines (25 loc) · 720 Bytes

scroll-handle.md

File metadata and controls

25 lines (25 loc) · 720 Bytes
滚动条位置处理
var scrollPosition = {
    // 位置
    result: 0,
    // 监听位置
    rememberPosition: function () {
        var type = 'scroll'
        var handle = function () {
            var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
            scrollPosition.result = scrollTop
        }
        if (window.addEventListener) {
            window.addEventListener(type, handle, false)
        }
        if (window.attachEvent) {
            window.attachEvent('on' + type, handle)
        }
    },
    // 设置位置
    setPostion: function () {
        window.scrollTo(document.body.scrollWidth, scrollPosition.result)
    }
}