You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1012 B
39 lines
1012 B
|
|
import store from '@/store' |
|
|
|
// 基准大小 |
|
const baseSize = 16; |
|
|
|
// 设置 rem 函数 |
|
const setRem = () => { |
|
// 当前页面宽度相对于 1920宽的缩放比例,可根据自己需要修改。 |
|
const scale = document.documentElement.clientWidth / 1920; |
|
// 设置页面根节点字体大小(“Math.min(scale, 2)” 指最高放大比例为2,可根据实际业务需求调整) |
|
document.documentElement.style.fontSize = baseSize * Math.min(scale, 2) + "px"; |
|
} |
|
|
|
const throttle = (func, delay) => { |
|
var prev = Date.now() |
|
return function () { |
|
var context = this; |
|
var args = arguments; |
|
var now = Date.now(); |
|
if (now - prev >= delay) { |
|
func.apply(context, args); |
|
prev = Date.now(); |
|
} |
|
} |
|
} |
|
|
|
const isMobile = () => { |
|
store.commit('layout/setMobile', /Mobi|Android|iPhone/i.test(navigator.userAgent) || window.innerWidth <= 640) |
|
} |
|
|
|
// 初始化 |
|
setRem(); |
|
isMobile() |
|
// 改变窗口大小时重新设置 rem |
|
window.onresize = throttle(() => { |
|
setRem(); |
|
isMobile() |
|
}, 500) |