移动DIV的功能? [英] Function to move a DIV?

查看:48
本文介绍了移动DIV的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有没有人有一个交叉浏览器功能,给出ID为DIV

元素,可以将DIV移动到绝对x ,y在屏幕上的位置?


谢谢, - 戴夫

Hi,

Does anyone have a cross-browser function that given an id of a DIV
element, can move the DIV to an absolute x,y position on the screen?

Thanks, - Dave

推荐答案

la *********** @ zipmail.com écrit:
la***********@zipmail.com a écrit :

有没有人有一个交叉浏览器函数给出一个ID为DIV

元素,可以将DIV移动到绝对x,y位置屏幕?
Does anyone have a cross-browser function that given an id of a DIV
element, can move the DIV to an absolute x,y position on the screen?



不在屏幕上,但在窗口中:


函数moveDiv(id,x,y){

id = document.getElementById(id);

id.style.position =''absolute'';

id.style.top = y + ''px'';

id.style.left = x +''px'';

document.body.appendChild(id);

}


-

ASM

Not on the screen, but in the window :

function moveDiv(id,x,y) {
id = document.getElementById(id);
id.style.position = ''absolute'';
id.style.top = y+''px'';
id.style.left = x+''px'';
document.body.appendChild(id);
}

--
ASM




ASM写道:

ASM wrote:
la ********** *@zipmail.com 一个écrit:
la***********@zipmail.com a écrit :

是否有人有一个跨浏览器功能给出ID为DIV

元素,可以将DIV移动到屏幕上的绝对x,y位置吗?
Does anyone have a cross-browser function that given an id of a DIV
element, can move the DIV to an absolute x,y position on the screen?



不在屏幕上,但在窗口中:


函数moveDiv(id,x,y){

id = document.getElementById(id);

id.style.position =''absolute'';

id.style.top = y + ''px'';

id.style.left = x +''px'';

document.body.appendChild(id);


Not on the screen, but in the window :

function moveDiv(id,x,y) {
id = document.getElementById(id);
id.style.position = ''absolute'';
id.style.top = y+''px'';
id.style.left = x+''px'';
document.body.appendChild(id);



除非OP有理由从DOM树中的当前位置移除

元素并放置它,否则最后一行是不必要的body元素的最后一个

子元素。我没有看到任何好处,它具有

的减法,使得将元素返回其原始位置更加困难(虽然没有'''已被声明为要求)。

-

Rob

The last line is unnecessary unless the OP has a reason to remove the
element from its current position in the DOM tree and place it the last
child of the body element. I can''t see any benefit in that, it has the
detraction of making it more difficult to return the element to its
original position (though that hasn''t been stated as a requirement).
--
Rob


RobG写道:
RobG wrote:

ASM写道:
ASM wrote:

> la *********** @ zipmail.com écrit:
>la***********@zipmail.com a écrit :

>>有没有人有一个跨浏览器功能给出一个DIV
元素的ID,可以将DIV移动到屏幕上的绝对x,y位置?
>>Does anyone have a cross-browser function that given an id of a DIV
element, can move the DIV to an absolute x,y position on the screen?


不在屏幕上,但在窗口中:

函数moveDiv(id,x,y){
id = document.getElementById( id);
id.style.position =''绝对'';
id.style.top = y +''px'';
id.style.left = x +''px '';
document.body.appendChild(id);


Not on the screen, but in the window :

function moveDiv(id,x,y) {
id = document.getElementById(id);
id.style.position = ''absolute'';
id.style.top = y+''px'';
id.style.left = x+''px'';
document.body.appendChild(id);



除非OP有理由从DOM树中的当前位置移除

元素并放置它,否则最后一行是不必要的

身体元素的最后一个孩子。我看不出任何好处,它可以让你更难以将元素

恢复到原来的位置(虽然没有''''被声明为

要求)。


The last line is unnecessary unless the OP has a reason to remove the
element from its current position in the DOM tree and place it the
last child of the body element. I can''t see any benefit in that, it
has the detraction of making it more difficult to return the element
to its original position (though that hasn''t been stated as a
requirement).



嗯,OP'在屏幕上''',我认为ASM在窗口中正确地改变了

到'' '',因为它真的不可能离开浏览器

窗口。该div可能有几个父元素,它们具有绝对或相对位置的
,这将影响div本身的定位。这将是相对于他们,而不是窗口。通过制作

确定它是来自身体的直接孩子,它将被定位在OP可能想要的

位置。

-

Rik Wasmus

Well, the OP sais ''on the screen'', and I think ASM correctly changed that
to ''in the window'', as it is not really possible to leave the browser
window. There could be several parent elements for that div, that have
either position absolute or relative, which will affect the positioning for
the div itself. It will be relative to them, not to the window. By making
sure it''s a direct child from the body it will be positioned on the
position the OP probably wants.
--
Rik Wasmus


这篇关于移动DIV的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆