日期:2014-05-16 浏览次数:20345 次
<div id='kk' style='border:solid 1px red;width:20px;height:20px;position:absolute;left:100px;top:100px'></div>
<div id='dpx' style="border: solid 1px;height: 1px;position: absolute;top: 370px;width: 100%"></div>
<script>
(function(div){
var nowspeed = 0; //当前速度
var niudun = 4.8; //(牛顿)加速度
var dpx= 350; //假定地平线坐标
var tx = .75; //弹性系数
var top = parseInt(div.style.top);
function run(){
var me = arguments.callee;
nowspeed+=niudun;
top+=nowspeed;
if(top>dpx){
//var d =
top = dpx - (top-dpx)*.7;
nowspeed *= -1*tx;
if(Math.abs(nowspeed)<1){
div.style.top = dpx+'px';
return;
}
}
div.style.top = top+'px';
setTimeout(run, 1000/10);
&n