JS实现tab标签功能

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf8" />
<title>简洁Tab</title>
<script src="http://www.powerbankpcba.com//templates/jscript/jquery.js" type="text/javascript"></script>

<style type="text/css">
.text_pro{ background:none;color:#333; font-family:"微软雅黑";}
.imging{ background:url(../images/product_tit_hover.jpg) no-repeat center; color:#ff0000;}
.pro_con{display:none;}
.pro_cont{}
</style>

<script language="javascript" type="text/javascript">
function news(ten,one){
	for(var i=0;i<2;i++){document.getElementById("con_"+ten+i).style.display="none";}
	for(var i=0;i<2;i++){document.getElementById("tit_"+ten+i).className="text_pro";}
	document.getElementById("tit_"+ten+one).className="imging";
	document.getElementById("con_"+ten+one).style.display="block";
}

$(function(){
for(h=0;h<2;h++){
$(".index_pro_tit a").eq(h).attr("onmouseover","setTimeout('news(2,"+h+")','100')");
};
})
</script>
</head>
<body>


<div class="index_pro_tit">
	<a class="text_pro imging" id="tit_20" href="#">Tab1</a>
    <a class="text_pro" id="tit_21" href="#">Tab2</a>
</div>

<div class="index_pro_con">
    <div class="pro_cont" id="con_20">
        测试内容1,在Tab1下
    </div>
    <div class="pro_con" id="con_21">
       测试内容2,在Tab2下
    </div>
</div>

</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的jQuery实现tab标签滑动切换效果的示例代码: HTML结构: ```html <div class="tab-wrap"> <ul class="tab-nav"> <li class="active">Tab1</li> <li>Tab2</li> <li>Tab3</li> <li>Tab4</li> </ul> <div class="tab-content"> <div class="tab-pane active">Tab1 Content</div> <div class="tab-pane">Tab2 Content</div> <div class="tab-pane">Tab3 Content</div> <div class="tab-pane">Tab4 Content</div> </div> </div> ``` CSS样式: ```css .tab-wrap { position: relative; } .tab-nav { display: flex; justify-content: space-between; } .tab-nav li { cursor: pointer; padding: 10px; font-size: 16px; font-weight: bold; border: 1px solid #ccc; border-bottom: none; } .tab-nav li.active, .tab-nav li:hover { background-color: #ccc; } .tab-content { position: absolute; top: 40px; left: 0; width: 100%; height: 200px; overflow: hidden; } .tab-pane { display: none; padding: 20px; } .tab-pane.active { display: block; } ``` JavaScript代码: ```javascript $(function() { // 获取tab标签和内容元素 var $tabNav = $(".tab-nav li"); var $tabContent = $(".tab-pane"); // 绑定tab标签点击事件 $tabNav.click(function() { // 获取点击的tab标签索引 var index = $(this).index(); // 切换tab标签的active类 $tabNav.removeClass("active"); $(this).addClass("active"); // 滑动切换tab内容 $tabContent.stop().animate({ "top": -index * $tabContent.height() }, 500); }); }); ``` 这段代码实现了以下功能: - 点击tab标签切换标签的active状态 - 滑动切换tab内容 注意:这只是一个简单的示例,具体实现方式可以根据需求进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值