2011年4月3号课程示例:JS动画最基本原理示例

日期:2011-04-03 21:39:11 点击:105

<!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/ecmascript">
function move(nTarget){
 
 var oDiv=document.getElementById('div1');
 if(nTarget>oDiv.offsetLeft){//向右走
 oDiv.style.left=oDiv.offsetLeft+10+"px";
 window.setTimeout("move("+nTarget+")",20);
 }else if(nTarget<oDiv.offsetLeft){
  oDiv.style.left=oDiv.offsetLeft-10+"px";
 window.setTimeout("move("+nTarget+")",20);
  
 }
 
}
</script>
</head>

<body>
<ul>
<li onclick="move(400);">1</li>
<li onclick="move(800);">2</li>
<li onclick="move(1200);">3</li>
</ul>
<div id="div1" style="width:100px; height:100px; background:yellow; position:absolute; top:110px; left:0;"></div>
</body>
</html>
 

上一篇: 返回列表

下一篇: javascript无缝滚动示例-动画-2011-4-3