老师,利用这种宽高比方式自适应方案可行吗?事先设定好大屏的宽高,也可以在屏幕上完整的展示啊
this.pWidth = document.documentElement.clientWidth
this.pHeight = document.documentElement.clientHeight
const w = this.$refs.bg.offsetWidth
const h = this.$refs.bg.offsetHeight
let scalX = this.pWidth / w
const scalY = this.pHeight / h
let ratio = scalX > scalY ? scalY : scalX
this.$refs.bg.style.transform = 'scale(' + ratio + ',' + ratio + ')'
const tLeft = (this.pWidth - w) / 2
const tTop = (this.pHeight - h) / 2
this.$refs.bg.style.left = tLeft + 'px'
this.$refs.bg.style.top = tTop + 'px'