原生JS滾動條位置處理


// 滾動條位置
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)
    }
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM