Tab标签式选项卡内容切换是比较常见的网页效果,这种方式能节约网页篇幅。我们常见的是用户点击或鼠标移至触发实现切换,而本文实例讲述的则是基于jQuery实现的定时自动切换tab效果。现在将实例代码分享给大家供大家参考,具体代码如下:html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
jQuery实现的tab标签自动切换效果* {
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;
}
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;
}
-
nav1
nav2
nav3
- 1111111111111111111111
- 2222222222222222222222
- 3333333333333333333333
$(document).ready(function(){
$('dt:first').addClass('active');
$('dd:first').css('display','block');
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');
$('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;
}
);
}