2010-04-27 112 views
0

使用javascript的滑动div水平移动div?

我有三个div与一些内容。我需要将div一个接一个地移动。移动DIV水平

任何想法..

+4

把更多的问号的称号!!!!! – fig 2010-04-27 13:05:50

+1

你应该考虑使用jQuery,而不是用普通的javascript编码。特别是如果你想让div移动到新的地方,而不是立即“跳过”那里。 – 2010-04-27 13:06:36

回答

3

您有权设置位置=绝对的,然后设置x和y的股利。您可以在javascript中更改它们的x和y。有很多可用的滑动脚本。

1

能这样进行:

// Moving the element to the 200 x 200 coordinate relative to 
// the parent element, WITHOUT JQUERY 

var elementStyles = document.getElementById("someDiv").style; 
elementStyles.position = "absolute"; 
elementStyles.top = 200 + "px"; 
elementStyles.left = 200 + "px"; 

// Moving the element to the 200 x 200 coordinate relative to 
// the parent element, WITH JQUERY 

$("#someDiv").animate({ 
    top: 200 + "px", 
    left: 200 + "px" 
}); 

// If the position should be changed relative to the current position, 
// add a `"+=" +` in front of `200` in the jQuery script, like this: 

left: "+=" + 200 + "px"