选项卡切换效果总结

Tab选项卡切换效果
切换类型:划过切换、点击切换、延迟切换、自动切换


划过切换:

window.οnlοad=function(){
	var li=document.getElementsByTagName("li");
	var nr=document.getElementsByName("content");
	for(var i=0;i<li.length;i++){
		li[i].index=i;
		li[i].οnmοuseοver=function(){
			for(var j=0;j<nr.length;j++){
				nr[j].style.display="none";				
			}
			nr[this.index].style.display="block";
		};
	}
}

点击切换:

window.οnlοad=function(){
		
      // 将所有点击的标题和要显示隐藏的列表取出来
      var menu=document.getElementById('menu'),
      p=menu.getElementsByTagName('p');
      ul=menu.getElementsByTagName('ul');
     // 遍历所有要点击的标题且给它们添加索引及绑定事件     
     if (p.length==ul.length) {
     	for(var i=0;i<p.length;i++){
     		p[i].id=i;
	     	p[i].οnclick=function(){
	     		//取点击的标题上的索引属性,根据该索引找到对应的列表
	     		// 判断该列表,如果是显示的则将其隐藏,如果是隐藏的则将其显示出来
	     		if (ul[this.id].style.display=='block') {
	     			ul[this.id].style.display='none';
	     		}else{
	     			ul[this.id].style.display='block';
	     		}
	     	}
     	}
     }  

}

延迟切换:

setTimeout延迟时间
在执行时,是在载入后延迟指定时间后,去执行一次表达式,仅执行一次
serInterval交互时间
在执行时,它从载入后,每隔指定的时间就执行一次表达式,下边显示的是这一种:

window.οnlοad=function(){
	    var send=document.getElementById('send'),
	        times=60,
	        timer=null;
	    send.οnclick=function(){
	      // 计时开始 
          timer=setInterval(autoCount,1000);       
	    }
        function autoCount(){
            send.value = times + "秒后重试";
            send.disabled = "false";
            times--;  
          
            if(times < 0){
                clearInterval(timer); 
                autoStop();
            }
        }
        
        function autoStop(){
            send.value = "发送验证码";
            send.removeAttribute("disabled");
            times = 60;
        }
}

自动切换:

window.onload = function() {
  var wrap = document.getElementById('wrap'),
    img = document.getElementById('pic').getElementsByTagName('li'),
    list = document.getElementById('list').getElementsByTagName('li'),
    index = 0,
    timer = null;
  // 定义并调用自动播放函数
  timer = setInterval(autoPlay, 2000);

  function autoPlay() {
    play(index);
    index++;
    if (index >= list.length) {
      index = 0;
    }
  }
  // 定义图片切换函数
  function play(curIndex) {
    for (var i = 0; i < list.length; i++) {
      list[i].className = '';
      img[i].style.display = 'none';
    }
    list[curIndex].className = 'on';
    img[curIndex].style.display = 'block';
    index = curIndex;
  }
  // 鼠标划过整个容器时停止自动播放
  wrap.onmouseover = function() {
    clearInterval(timer);
  };
  // 鼠标离开整个容器时继续播放至下一张
  wrap.onmouseout = function() {
    timer = setInterval(autoPlay, 2000);
  };
  // 遍历所有数字导航实现划过切换至对应的图片
  for (var i = 0; i < list.length; i++) {
    list[i].id = i;
    list[i].onmouseover = function() {
      play(this.id);
    };
  }
};

高亮:li.select,class="select"

添加索引:titles[i].id=i;

setTimeout是window属性,其内this指window。若要使用原this,需要赋值

Tab自动切换 清空定时器,防止反应不灵敏


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值