先创建一个js文件,编写好该方法。之后页面哪里需要就直接引入
/*
* 弹窗偏移
* x 偏移x轴坐标
* e 要显示的dialog的id
* */
function deviation(x, e, margin = '128px 0 0') {
const dialog = document.getElementById(e).children[0]
let left = x - dialog.clientWidth / 2
const boundary = x + dialog.clientWidth / 2
if (left < 0) {
left = 0
} else if (boundary > 15360) {
left = 15000 - dialog.clientWidth / 2
}
dialog.style.left = `${left}px`
dialog.style.margin = margin
}
import { deviation } from '文件的地址'
iconClick(event) {
const x = e.x
this.$nextTick(() => {
deviation(x, 'dom的ID')
})
},