tab选项卡切换效果(三)——自动切换加滑动切换



<script>
    function $(id){
        return typeof id==='string'?document.getElementById(id):id;
    }
    window.onload=tab;
    function tab(){
        //当前高亮显示的页签的索引
        var index=0;
        var timer=null;
        //获取所有的页签和要切换的内容
        var lis=$('notice_tit').getElementsByTagName('li');
        var divs=$('notice_con').getElementsByTagName('div');
        //遍历每一个页签且给他们绑定事件
        for (var i=0;i<lis.length;i++){
            lis[i].id=i;
            lis[i].onmouseover=function(){
                clearInterval(timer);
                changeOption(this.id);
            }
            lis[i].onmouseout=function(){
                timer=setInterval(autoPlay,2000);
            }
        }
        if (timer){
            clearInterval(timer);
            timer=null;
        }
        //添加定时器,改变当前高亮的索引
        timer=setInterval(autoPlay,2000);
        function autoPlay(){                      //封装函数方便调用
            index++;
            if (index>=lis.length){
                index=0;
            }
            changeOption(index);
        }
        function changeOption(curIndex){           //封装函数方便调用
            for (var j=0;j<lis.length;j++){
                lis[j].className='';
                divs[j].style.display='none';
            }
            //高亮显示当前页签
            lis[curIndex].className='select';
            divs[curIndex].style.display='block';
            index=curIndex;
        }
    }
</script>
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值