【发布时间】:2021-06-27 14:37:26
【问题描述】:
我有一个 vue 应用程序,我在其中创建了一些方法来将我的 div“工具箱”移动到 DOM 的不同部分。目前,DIV 加载在屏幕的右下角,它是静态的,如果我滚动页面,它不会移动。
我创建的方法试图实现相同的目标,但是将 DIV 移动到“左上角”、“右上角”、“左下角”,并且在找到要赋予的正确 px 值时遇到了一些问题给定的功能。有谁知道是否有更好的方法来做到这一点?
我的代码:
<button @click="changePositionTopLeft">Move Top Left</button>
<button @click="changePositionTopRight">Move Top Right</button>
<button @click="changePositionBottomLeft">Move Bottom Left</button>
methods: {
changePositionTopLeft() {
const divPosition = document.getElementById('sdk-ts-root')
divPosition.style.left = '200px'
divPosition.style.top = '200px'
},
changePositionTopRight() {
const divPosition = document.getElementById('sdk-ts-root')
divPosition.style.right = '400px'
divPosition.style.top = '400px'
},
changePositionBottomLeft() {
const divPosition = document.getElementById('sdk-ts-root')
divPosition.style.left = '400px'
divPosition.style.bottom = '400px'
}
} }
【问题讨论】:
标签: javascript css vue.js position css-position