tab选项卡自动切换,带焦点

废话不多说,上代码,jq自己个就可以了.

<!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=utf-8" />
<title>jQuery实现的tab标签自动切换效果</title>
<style type="text/css">
* {
 margin:0;
 padding:0;
}
dl {
 margin:10px auto;
 width:500px;
 line-height:24px;
 border-left:1px solid #dcdcdc;
}
dt.active {
 border-bottom:1px solid #fff;
 position:relative;
 background:red;
 color: #fff;
}
dt {
 padding:0 10px;
 float:left;
 border:1px solid #dcdcdc;
 border-left:0;
 cursor:pointer;
 margin-bottom:-1px;
}
dd {
 clear:both;
 width:100%;
 border-left:0;
 border:1px solid #dcdcdc;
 border-left:0;
 display:none;
}
ul{
  width: 500px;
  margin:0 auto;
}
ul li{
  width: 20px;
  height: 20px;
  border: 1px solid #ccc;
  background: #ccc;
  border-radius: 50%;
  float: left;
  list-style: none;
  margin: 0 10px;
}
ul li.active {
 border:1px solid red;
 background: red;
}

</style>
</head>
<body>
<dl>
  <dt>nav1</dt>
  <dt>nav2</dt>
  <dt>nav3</dt>
  <dd>1111111111111111111111</dd>
  <dd>2222222222222222222222</dd>
  <dd>3333333333333333333333</dd>
</dl>
<ul>
  <li></li>
  <li></li>
  <li></li>
</ul>
<script type="text/javascript" src="style/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
   $('dt:first').addClass('active');
   $('dd:first').css('display','block');
   $('ul li:first').addClass('active');
   autoroll();
   hookThumb();
});
var i=-1; //第i+1个tab开始
var offset = 2500; //轮换时间
var timer = null;
function autoroll(){
 n = $('dt').length-1;
 i++;
 if(i > n){
 i = 0;
 }
 slide(i);
    timer = window.setTimeout(autoroll, offset);
 }
function slide(i){
 $('dt').eq(i).addClass('active').siblings().removeClass('active');
 $('li').eq(i).addClass('active').siblings().removeClass('active');
 $('dd').eq(i).css('display','block').siblings('dd').css('display','none');
 }
function hookThumb(){    
 $('dt').hover(
    function () {
      if (timer) {
                  clearTimeout(timer);
      i = $(this).prevAll().length;
               slide(i); 
              }
    },
    function () {
        
              timer = window.setTimeout(autoroll, offset);  
              this.blur();            
              return false;
    }
  ); 
 $('li').hover(
    function () {
      if (timer) {
                  clearTimeout(timer);
      i = $(this).prevAll().length;
               slide(i); 
              }
    },
    function () {
        
              timer = window.setTimeout(autoroll, offset);  
              this.blur();            
              return false;
    }
  ); 
}
</script>
</body>
</html>

效果图(小编为了实现效果,只做了简版的,足够小编使用)
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值