以下这段是JQUERY控制DIV位置变化的代码。可以运行,但是除了top, left相对于原位置的相对变化外,是否还有DIV动画绝对位置的设置,类似于 $('.div1').css({ top: 0 , left: 0 }); ?比如animate之后,DIV1新的坐标位置为(0,0),DIV2新的坐标位置为(300,0),DIV3新的坐标位置为(200,0)。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> </title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<style type="text/css">
body{width:100%;height:100%;margin:0;padding:0;}
.content{width:600px;margin-left:auto;margin-right:auto;padding:0;}
.div1,.div2,.div3,.div4{float:left; width:300px; height:200px;margin:0;padding:0;position:relative;}
</style>
</head>
<body>
<div class="content">
<div id="div4"><div class="div4" style="background-color:#0f0;"><a href="#" class="click">4</a>
</div></div>
<div id="div3"><div class="div3" style="background-color:#f00;"><a href="#" class="click">3</a>
</div></div>
<div id="div2"><div class="div2" style="background-color:#0ff;"><a href="#" class="click">2</a>
</div></div>
<div id="div1"><div class="div1" style="background-color:#ff0;"><a href="#" class="click">1</a>
</div></div>
</div>
<script type="text/javascript">
$(function() {
$('.click').bind('click', function(){
$('.div1').stop().animate({ top: -200 , left: -300 });
$('.div2').stop().animate({ top: -200 , left: 300 });
$('.div3').stop().animate({ top: 200 , left: -300 });
$('.div4').stop().animate({ top: 200 , left: 300 });
});
});
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> </title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<style type="text/css">
body{width:100%;height:100%;margin:0;padding:0;}
.content{width:600px;margin-left:auto;margin-right:auto;padding:0;}
.div1,.div2,.div3,.div4{float:left; width:300px; height:200px;margin:0;padding:0;position:relative;}
</style>
</head>
<body>
<div class="content">
<div id="div4"><div class="div4" style="background-color:#0f0;"><a href="#" class="click">4</a>
</div></div>
<div id="div3"><div class="div3" style="background-color:#f00;"><a href="#" class="click">3</a>
</div></div>
<div id="div2"><div class="div2" style="background-color:#0ff;"><a href="#" class="click">2</a>
</div></div>
<div id="div1"><div class="div1" style="background-color:#ff0;"><a href="#" class="click">1</a>
</div></div>
</div>
<script type="text/javascript">
$(function() {
$('.click').bind('click', function(){
$('.div1').stop().animate({ top: -200 , left: -300 });
$('.div2').stop().animate({ top: -200 , left: 300 });
$('.div3').stop().animate({ top: 200 , left: -300 });
$('.div4').stop().animate({ top: 200 , left: 300 });
});
});
</script>
</body>
</html>
可以参考这个