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

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


<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>nav1dt>
  <dt>nav2dt>
  <dt>nav3dt>
  <dd>1111111111111111111111dd>
  <dd>2222222222222222222222dd>
  <dd>3333333333333333333333dd>
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>

效果图(小编为了实现效果,只做了简版的,足够小编使用)
tab选项卡自动切换,带焦点_第1张图片

你可能感兴趣的:(tab选项卡,自动切换,焦点奇幻)