js鼠标点击展开收起特效(带缓动效果)

这款网页特效还不错  兼容性很好! 大气阿 

转自: JS特效

代码如下

<html>
<head>
<title>鼠标点击展开收起效果(带缓动效果)-网页特效代码</title>
<style type="text/css">
.box{width:300px;border:1px solid #ccc;font-size:12px}
.box dt{line-height:24px;text-align:right;margin:0;padding:0 10px;background:#CCC}
.box dd{line-height:20px;margin:0}
#holder2{height:200px}
</style>
</head>
<body>
<dl class="box">
    <dt id="title">点击展开/收起</dt>
    <dd id="holder">
鼠标点击展开收起效果(带缓动效果2)-网页特效代码网
    </dd>
</dl>
<br>
<dl class="box">
    <dt id="title2">点击展开/收起</dt>
    <dd id="holder2">
鼠标点击展开收起效果(带缓动效果3)-网页特效代码网
    </dd>
</dl>
<script type="text/javascript">
/*
*  id:展开/收起内容区的id
*  minH : 展开/收起的最小高度
*  maxH : 展开/收起的最大高度
*  expand : true - 从收起到展开、false - 从展开到收起
*  rate : 缓动变化率 0-1
*  speed : 速度(毫秒)
*/
var Toggle = function(id, minH, maxH, expand, rate, speed){
    this.minH = minH;
    this.maxH = maxH;
    this.tempH = 0;
    this.rate = rate;
    this.speed = speed;
    this.moving = false;
    this.moveT = null;
    this.holder = document.getElementById(id);
    this.expand = expand;
}
Toggle.prototype = {
    start : function(){
        if(this.moving) return;
        this.moving = true;
        this.tempH = this.expand ? this.minH : this.maxH;
        var t = this;
        this.moveT = setInterval(function(){t.move()}, this.speed);
    },
    move : function(){
        if(this.expand){
            if(this.tempH >= this.maxH){
                this.moving = false;
                this.expand = false;
                clearInterval(this.moveT);
            }else{
                var h = Math.round((this.maxH - this.tempH) * this.rate);
                if(h <= 1){
                    h = 1;
                }
                this.tempH += h;
            }
        }else{
            if(this.tempH <= this.minH){
                this.moving = false;
                this.expand = true;
                clearInterval(this.moveT);
            }else{
                var h = Math.round((this.tempH - this.minH) * this.rate);
                if(h <= 1){
                    h = 1;
                }
                this.tempH -= h;
            }
        }
        this.holder.style.height = this.tempH + "px";
    }
}
//版块一(默认已收起)
var obj = new Toggle("holder",20,200,true, 0.2, 10);
document.getElementById("title").onclick = function(){
    obj.start();
}
//版块二(默认已展开)
var obj2 = new Toggle("holder2",20,200,false, 0.2, 10);
document.getElementById("title2").onclick = function(){
    obj2.start();
}
</script>
</body>
</html>
       


岩石地址:http://www.iiwnet.com/js_window/304.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值