tab栏
var tabb1=document.getElementsByClassName("tabb");
var main2=document.getElementsByClassName("main1");
for (var i = 0; i < tabb1.length; i++) {
tabb1[i].index=i;
tabb1[i].onmouseover=handmouseover;
}
function handmouseover(){
for (var j = 0; j < main2.length; j++) {
main2[j].className="main1";
}
main2[this.index].className="main1 img1"
}
index .html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<style lang="box">
*{
padding: 0;
margin: 0;
list-style: none;
}
.tab{
width: 400px;
height: 30px;
line-height: 30px;
border: 1px solid #f00;
}
.tab ul{
text-align: center;
}
.tab ul li{
width: 100px;
height: 30px;
float: left;
position: relative;
overflow: hidden;
}
.tab li span{
position: absolute;
width: 1px;
height:14px;
display: block;
background: #999;
right: 0;
top:8px;
}
.main{
width: 1000px;
height: 475px;
border:1px solid #f0f;
overflow: hidden;
}
.main1{
display: none;
float: left;
}
.img1{
display: block;
}
</style>
<title>Document</title>
</head>
<body>
<div class="tab">
<ul>
<li class="tabb">
<p>国际大牌</p>
<span>△</span>
</li>
<li class="tabb">
<p>国妆名牌</p>
<span>△</span>
</li>
<li class="tabb">
<p>清洁用品</p>
<span>△</span>
</li>
<li class="tabb">
<p>男士精品</p>
</li>
</ul>
</div>
<div class="main">
<div class="main1 img1">
<img src="./img/guojidapai.jpg" alt="">
</div>
<div class="main1 ">
<img src="./img/guozhuangmingpin.jpg" alt="">
</div>
<div class="main1 ">
<img src="./img/nanshijingpin.jpg" alt="">
</div>
<div class="main1 ">
<img src="./img/qingjieyongpin.jpg" alt="">
</div>
</div>
</body>
<script>
var tabb1=document.getElementsByClassName("tabb");
var main2=document.getElementsByClassName("main1");
for (var i = 0; i < tabb1.length; i++) {
tabb1[i].index=i;
tabb1[i].onmouseover=handmouseover;
}
function handmouseover(){
for (var j = 0; j < main2.length; j++) {
main2[j].className="main1";
}
main2[this.index].className="main1 img1"
}
</script>
</html>
来源:https://www.cnblogs.com/Lovevr/p/8328167.html