当前位置:网站首页>tab栏切换样式
tab栏切换样式
2022-07-19 16:51:00 【我若成魔,佛赖我何,我就是程序狂魔】
JS代码
<script>
function tablan(){
let ul=document.querySelector(".nav ul")
let lis=ul.querySelectorAll('.nav ul li');
let div=document.querySelectorAll('.nav .conter div');
//遍历所有li
for(i=0;i<lis.length;i++){
lis[i].setAttribute("index",i)//给每个li设置索引
//给li绑定点击事件
lis[i].onclick=function(){
//获得当前索引
for(j=0;j<lis.length;j++){
//先清除li的样式
lis[j].className='';
//隐藏div
div[j].style.display='none';
}
//当点击当前的li给这个li添加tab-1样式
this.className='tab-1';
//当鼠标点击这个属性就是当前这个索引
let thisIndex=this.getAttribute("index");
//点击li当前的div和li索引相同的div显示
div[thisIndex].style.display="block";
}
}
}
tablan();
</script>
<style>
*{
margin: 0px;
padding: 0px;
}
a{
text-decoration: none;
}
.nav{
width:1200px;
margin: 40px auto;
border: 1px solid gray;
position: relative;
}
/* .nav>ul::after{
content: '';
display: block;
clear: both;
} */
.nav>ul{
width: 1200px;
list-style: none;
display: flex;
justify-content: space-around;
}
.nav>ul>li{
width: 200px;
height: 60px;
text-align: center;
line-height: 60px;
background: pink;
/* float: left; */
}
.nav>ul>.tab-1{
background: blue;
}
.nav>ul>li>a{
color: grey;
}
.nav>.conter{
width: 1200px;
height: 800px;
overflow: hidden;
/* border: 1px solid gray; */
position: absolute;
top: 60px;
left: 0px;
}
.nav>.conter>div{
width: 1200px;
height: 800px;
border: 1px solid gray;
box-sizing: border-box;
text-align: center;
font-size: 40px;
line-height: 800px;
}
</style>
<div class="nav">
<ul>
<li class="tab-1">
<a href="javascript:;">
新闻页面
</a>
</li>
<li>
<a href="javascript:;">
菜单栏
</a>
</li>
<li>
<a href="javascript:;">
信息服务
</a>
</li>
<li>
<a href="javascript:;">
资讯业务
</a>
</li>
</ul>
<div class="conter">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</div>
边栏推荐
- MATLAB and 1stOpt multivariate nonlinear regression
- 批量下载数据——以TRMM数据为例
- 降水数据汇总
- Rambus宣布面向数据中心和PC的DDR5内存接口芯片产品组合
- Matlab calculates the distance between two points (longitude and latitude coordinates) (large arc method and haversine method)
- Leetcode 115.不同的子序列
- 地学学术资源II
- WPF RadioButton样式 (2)
- shell跑数命令
- Matlab TRMM_3B42数据格式转换(nc转tif,附代码)
猜你喜欢
随机推荐
Rambus宣布面向数据中心和PC的DDR5内存接口芯片产品组合
云上机器CLOSE_WAIT过多的原因和解决办法
Interviewer: what are the three cache update strategies of redis & MySQL?
npm配置淘宝镜像
CodeForces 1417B Two Arrays
What is the basic principle of MySQL read / write separation
批量下载数据——以TRMM数据为例
150. 逆波兰表达式求值
浏览器兼容性问题及常见的解决方法
地学学术资源(常用数据及其下载地址)
Matlab填充影像中的无效值
Pycharm Debug错误“Process finished with exit code -1073741819 (0xC0000005)”解决方案
Avalonia—netcore 图片处理
Huayun data won the outstanding contribution enterprise of sustainable technological innovation
JVM 上数据处理语言的竞争:Kotlin, Scala 和 SPL
arcpy批量转换数据投影(以Albers为例)
LeetCode 剑指offer刷题笔记
【Codeforces1706A】 Another String Minimization Problem
MSWEP数据nc格式转tif格式
背后的力量 | 加强数字政府建设 华云数据助力华中某省民政厅提升便民服务能力