其他分享
首页 > 其他分享> > pc宽度缩放环境判断

pc宽度缩放环境判断

作者:互联网

import Store from '@/store'     const setBodyClass = (...cls) => { document.body.classList.remove(...['ipad', 'h5', 'pc', 'small-pc', 'big-pc', 'not-h5']) document.body.classList.add(...cls) }
  function setIsMobile () { const screenWidth = document.documentElement.clientWidth if ((screenWidth < 1280 && screenWidth >= 768)) { Store.commit('SET_SCREEN_STATUS', 'ipad') setBodyClass('ipad', 'not-h5') } else if (screenWidth < 768) { /** * width小于775判定为移动端,参考币安 */ Store.commit('SET_SCREEN_STATUS', 'h5') setBodyClass('h5') } else if (screenWidth < 1540) { Store.commit('SET_SCREEN_STATUS', 'smallPc') setBodyClass('pc', 'small-pc', 'not-h5') } else { Store.commit('SET_SCREEN_STATUS', 'bigPc') setBodyClass('pc', 'big-pc', 'not-h5') } } setIsMobile() window.addEventListener('resize', setIsMobile)

标签:setBodyClass,SET,缩放,h5,pc,宽度,screenWidth,Store
来源: https://www.cnblogs.com/zerofan/p/15975124.html