jquery写tab切换,有过渡效果

效果:
在这里插入图片描述
根据自己项目更改
代码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			ul,li {
				list-style: none;
				margin: 0;
				padding: 0;
			}
			.tabBox {
				width: 400px;
				height: 200px;
				border: 1px solid pink;
			}
			.ul1 {
				height: 40px;
				border-bottom: 1px solid pink;
			}
			.ul1 li {
				width: 25%;
				line-height: 40px;
				text-align: center;
				float: left;
				cursor: pointer;
			}
			.ul1 li.active {
				background-color: pink;
				transition: all 0.6s ease-in-out;  /* 标题过渡效果 */
				position: relative;
			}
			.ul1 li.active::after {
				content: "";
				position: absolute;
				bottom: 3px;
				left: 50%;
				transform: translateX(-50%);
				width: 30%;
				height: 5px;
				background-color: red;
			}
			.ul2 {
				overflow: hidden;
			}
			.ul2 li {
				display: none;
			}
			.ul2 li.selected {
				display: block;
			}
		</style>
	</head>
	<body>
		<div class="tabBox">
			<ul class="ul1">
				<li class="active">标题1</li>
				<li>标题2</li>
				<li>标题3</li>
				<li>标题4</li>
			</ul>
			<ul class="ul2">
				<li class="selected">内容内容1</li>
				<li>内容2内容2</li>
				<li>内容3内容3</li>
				<li>内容4内容4</li>
			</ul>	
		</div>
		<script type="text/javascript" src="jquery-2.1.1.js"></script>
		<script>
			$(function(){
				$(".ul1>li").mouseover(function(){
					$(this).addClass("active active::after").siblings("li").removeClass("active");
					var index = $(this).index();
					$(".ul2>li:eq("+index+")").fadeIn(1000).siblings("li").hide(); 
				})
			}) 
		</script>
	</body>
</html>

或者

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值