缓冲效果

<!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=gb2312" />
<title>缓冲</title>
<style>
.divname{ width:400px; height:100px;overflow:hidden;background:#f30; margin:0 auto;}
span{float:left;display:block;padding:5px; cursor:pointer;}
</style>
<script>
//选择器
function $(id,tag){var re=(id&&typeof id!="string")?id:document.getElementById(id);if(!tag){return re;}else{return re.getElementsByTagName(tag);}}

//========================================================================
//id:对象id
//butid:按钮id
//dir:1为水平方式,2为上下方式
//fnum:最终目标值
//mouse:鼠标事件
//sp:速度
var tt;
function Unfold(id,butid,dir,fnum,mouse,sp){
$(butid)[mouse]=function(){clearInterval(tt);tt=setInterval(mov,5);} //鼠标事件执行效果
function mov(){
var idwh=(dir==1)?parseInt($(id).offsetWidth):parseInt($(id).offsetHeight); //得到容器的宽或高
var v=(fnum<idwh)?Math.floor((fnum-idwh)/sp):Math.ceil((fnum-idwh)/sp); //算出每次运动量
(dir==1)?$(id).style.width=idwh+v+"px":$(id).style.height=idwh+v+"px";
if (v==0){clearInterval(tt);}
$("abc").innerHTML=idwh+"<br>";
}
}
</script>
</head>

<body>
<div style="clear:both; height:30px;">
<span id="but1">左右展开</span>
<span id="but2">左右缩起</span>
<span id="but3">上下展开</span>
<span id="but4">上下缩起</span>
<span id="abc"></span>
</div>


<div class="divname" id="divid"></div>
<script>Unfold("divid","but1",1,900,"onclick",6);</script>
<script>Unfold("divid","but2",1,10,"onclick",6);</script>
<script>Unfold("divid","but3",2,500,"onclick",6);</script>
<script>Unfold("divid","but4",2,10,"onclick",6);</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值