2010-04-27 141 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"