水平移动div?

时间:2010-04-27 13:02:05

标签: javascript html

使用javascript滑动div

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

任何想法..

3 个答案:

答案 0 :(得分:3)

你必须设置position = absolute,然后为div设置x和y。你可以在javascript中更改他们的x和y。有很多可用的滑动脚本。

答案 1 :(得分: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"

答案 2 :(得分:0)

您可以使用jQuery以及slideDown()slideUp()函数。见http://api.jquery.com/category/effects/sliding/