js在网页上的一大特色应用就是js动画效果,为了让效果看起来更加平滑,增进用户体验,缓动公式是必不可少的。一个不带缓冲的动画效果:
<
div
style
="background:silver;border:solid 1px #999999;width:100px;height:50px;position:relative"
onclick
="change.call(this)"
>
</ div >
< script > ...
function change()
...{
var me=this;
var begin=new Date();
function f(t)...{
return 50+t/2;
}
var timeHandle=setInterval(function()...{
var t=new Date()-begin;
me.style.height=Math.floor(f(t))+"px";
},10);
setTimeout(function()...{
clearTimeout(timeHandle);
me.style.height=Math.floor(f(1000))+"px";
},1000);
change=Function.prototype;
}
</ script >
</ div >
< script > ...
function change()
...{
var me=this;
var begin=new Date();
function f(t)...{
return 50+t/2;
}
var timeHandle=setInterval(function()...{
var t=new Date()-begin;
me.style.height=Math.floor(f(t))+"px";
},10);
setTimeout(function()...{
clearTimeout(timeHandle);
me.style.height=Math.floor(f(1000))+"px";
},1000);
change=Function.prototype;
}
</ script >