yyman001 / blog

日常疑问记录解答
5 stars 0 forks source link

获取绝对准确的滚动条宽度 #32

Open yyman001 opened 6 years ago

yyman001 commented 6 years ago
      getScrollSize (){

        // Create the measurement node
        var scrollDiv = document.createElement("div")
        scrollDiv.className = "scrollbar-size"
        // scrollDiv.style.overflow = 'scroll'
        document.body.appendChild(scrollDiv)

        // Get the scrollbar width
        this.scrollSize = scrollDiv.offsetWidth - scrollDiv.clientWidth
        // Mac:  15
        // Delete the DIV
        document.body.removeChild(scrollDiv)
        this.zoomBarStyle.right = this.scrollSize + 'px'
        this.zoomBarStyle.bottom = this.scrollSize + 'px'
        console.warn('this.zoomBarStyle:', this.zoomBarStyle)
      },

https://davidwalsh.name/detect-scrollbar-width http://blog.csdn.net/hdchangchang/article/details/8251610