JQ tab标签页

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tab1</title>
<style type="text/css">
*{ 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;}
</style>
</head>
<body>
<!-- 这里是标签标题 -->
<div class="tabTitle">
    <ul>
        <li class="current">xhtml</li>
        <li>css</li>
        <li>jquery</li>
    </ul>
</div>
<div class="tabContent">
    <div>xhtml的内容</div>
    <div class="hide">css的内容</div>
    <div class="hide">jquery的内容</div>
</div>
<script src="jquery.js"></script>
<script type="text/javascript">
$(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);
	});
});
</script>
</body>
</html>

效果图:

 

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tab2</title>
<style type="text/css">
*{ 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;}
.current0{ background: #abcdef; color:#fff;}
.current1{ background: red; color:teal;}
.current2{ background: green; color:yellow;}
.tabContent div{ border: 1px solid #f60; width: 300px; height: 250px; padding: 15px;}
</style>
</head>
<body>
<!-- 这里是标签标题 -->
<div class="tabTitle">
    <ul>
        <li class="current0">xhtml</li>
        <li>css</li>
        <li>jquery</li>
    </ul>
</div>
<div class="tabContent">
    <div>xhtml的内容</div>
    <div class="hide">css的内容</div>
    <div class="hide">jquery的内容</div>
</div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(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(function(){
				return 'current'+_this.index();
			}).siblings().removeClass();
			//如果想用一组元素控制另一组元素的显示或者隐藏,需要用到索引
			var index = _this.index();
			aDiv.eq(index).show().siblings().hide();
		},300);
	}).mouseout(function(){
		//clearTimeout的作用是清除定时器
		clearTimeout(timeId);
	});
});
</script>
</body>
</html>

 效果图:

 

猜你喜欢

转载自onestopweb.iteye.com/blog/2285651
jq
今日推荐