Script its left
and top
properties as the number of pixels from the left edge and top edge respectively.(将其left
和top
属性分别编写为左边缘和上边缘的像素数。)
It must have position: absolute;
(它必须有position: absolute;
)
var d = document.getElementById('yourDivId');
d.style.position = "absolute";
d.style.left = x_pos+'px';
d.style.top = y_pos+'px';
Or do it as a function so you can attach it to an event like onmousedown
(或者将其作为一个函数执行,以便将其附加到onmousedown
事件上)
function placeDiv(x_pos, y_pos) {
var d = document.getElementById('yourDivId');
d.style.position = "absolute";
d.style.left = x_pos+'px';
d.style.top = y_pos+'px';
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…