首页 > 代码库 > javascrpt获取滚动条的宽度

javascrpt获取滚动条的宽度

function getScrollBarHW() {

            if (this.scrollBarHW) {

                return this.scrollBarHW;

            }

            var div = document.createElement(‘div‘);

            div.style.overflow = ‘scroll‘;

            div.style.visibility = ‘hidden‘;

            div.style.position = ‘absolute‘;

            div.style.width = ‘100px‘;

            div.style.height = ‘100px‘;

            document.body.appendChild(div);

 

            this.scrollBarHW = {

                width : div.offsetWidth - div.clientWidth,

            };

            div.parentNode.removeChild(div);

            return this.scrollBarHW.width;

        }

   alert(getScrollBarHW())

javascrpt获取滚动条的宽度