getBoundingClientRect

((win)=>{

var tid,
      refreshWidth = () => {
        var cliR = win.document.documentElement.getBoundingClientRect()   //
        var width=cliR.width
        var height=cliR.height
        win.clearTimeout(tid);
        tid=win.setTimeout(console.log(width),300)
}

win.addEventListener('resize',()=>{
    refreshWidth()
})
win.addEventListener('pageshow',(e) => {  //onload 之后 初始化显示
    if(e.persisted){          //从缓存加载
        refreshWidth()
    }
})

})(window)

你可能感兴趣的:(getBoundingClientRect)