本文实例讲述了jQuery实现简单的tab标签页效果。分享给大家供大家参考,具体如下:
tab1*{ padding: 0; margin: 0;}
li{ list-style-type: none;}
body{ margin: 50px;}
.hide{ display: none;}
.tabTitle ul{ overflow: hidden; _height:1px;}
.tabTitle ul li{ float: left; border: 1px solid #abcdef; border-bottom: none; height: 30px; line-height: 30px; padding: 0 15px; margin-right: 3px; cursor:pointer;}
.current{ background: #abcdef; color:#fff;}
.tabContent div{ border: 1px solid #f60; width: 300px; height: 250px; padding: 15px;}
- xhtml
- css
- jquery
$(function(){
var ali = $('.tabTitle ul li');
var aDiv = $('.tabContent div');
var timeId = null;
ali.mouseover(function(){
var _this = $(this);
//setTimeout();的作用是延迟某一段代码的执行
timeId = setTimeout(function(){
//$(this)方法属于哪个元素,$(this)就是指哪个元素
_this.addClass('current').siblings().removeClass('current');
//如果想用一组元素控制另一组元素的显示或者隐藏,需要用到索引
var index = _this.index();
aDiv.eq(index).show().siblings().hide();
},300);
}).mouseout(function(){
//clearTimeout的作用是清除定时器
clearTimeout(timeId);
});
});
运行效果图如下:
希望本文所述对大家jQuery程序设计有所帮助。