当前位置:网站首页>Web APIs 综合案例-Tab栏切换 丨黑马程序员
Web APIs 综合案例-Tab栏切换 丨黑马程序员
2022-06-30 20:10:00 【黑马程序员官方】
学过了以上内容,今天我们来做一个综合的案例:Tab栏切换

分析:
html代码:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8" />
<title></title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
.wrapper {
width: 1000px;
height: 475px;
margin: 0 auto;
margin-top: 100px;
}
.tab {
border: 1px solid #ddd;
border-bottom: 0;
height: 36px;
width: 320px;
}
.tab li {
position: relative;
float: left;
width: 80px;
height: 34px;
line-height: 34px;
text-align: center;
cursor: pointer;
border-top: 4px solid #fff;
}
.tab span {
position: absolute;
right: 0;
top: 10px;
background: #ddd;
width: 1px;
height: 14px;
overflow: hidden;
}
.products {
width: 1002px;
border: 1px solid #ddd;
height: 476px;
}
.products .main {
float: left;
display: none;
}
.products .main.active {
display: block;
}
.tab li.active {
border-color: red;
border-bottom: 0;
}
</style>
</head>
<body>
<div class="wrapper">
<ul class="tab">
<li class="tab-item active">国际大牌<span>◆</span></li>
<li class="tab-item">国妆名牌<span>◆</span></li>
<li class="tab-item">清洁用品<span>◆</span></li>
<li class="tab-item">男士精品</li>
</ul>
<div class="products">
<div class="main active">
<a href="###"><img src="imgs/guojidapai.jpg" alt="" /></a>
</div>
<div class="main">
<a href="###"><img src="imgs/guozhuangmingpin.jpg" alt="" /></a>
</div>
<div class="main">
<a href="###"><img src="imgs/qingjieyongpin.jpg" alt="" /></a>
</div>
<div class="main">
<a href="###"><img src="imgs/nanshijingpin.jpg" alt="" /></a>
</div>
</div>
</div>
<script>
// 0. 获取元素
// 得到所有的小li
let lis = document.querySelectorAll('.tab .tab-item')
let divs = document.querySelectorAll('.products .main')
// 1. 头部tab栏切换模块
// 1.1 先给4个小li添加点击事件
for (let i = 0; i < lis.length; i++) {
lis[i].addEventListener('click', function () {
// console.log(11)
// 找到以前的active 类,移除掉
document.querySelector('.tab .active').classList.remove('active')
// 当前的元素添加
this.classList.add('active')
// 2. 底部显示隐藏模块 一定要写到点击事件的里面
document.querySelector('.products .active').classList.remove('active')
// div对应序号的那个加上active
divs[i].classList.add('active')
})
}
</script>
</body>
</html>素材图片:



你做的怎么样呢?评论去可以告诉我哦~~
黑马前端专栏干货多多,关注再学,好方便~
2022年前端学习路线图:课程、源码、笔记,技术栈 另外此线路图实时更新!需要课后资料的友友们,可以直接告诉我。

边栏推荐
- Build your own website (20)
- 左值引用和右值引用
- Jerry's determination of detection sensitivity level [chapter]
- Heartbeat uses NFS to make MySQL highly available based on CRM
- The newly born robot dog can walk by himself after rolling for an hour. The latest achievement of Wu Enda's first disciple
- Implementation principle of PostgreSQL heap table storage engine
- obsidian配合hugo的使用,让markdown本地编辑软件与在线化无缝衔接
- Lambda 表达式原理分析学习(2022.06.23)
- GeoServer installation
- PM这样汇报工作,老板心甘情愿给你加薪
猜你喜欢

Evolution of screen display technology

NLP 论文领读|文本生成模型退化怎么办?SimCTG 告诉你答案

To eliminate bugs, developers must know several bug exploration and testing artifacts.

Is the project manager a leader? Can you criticize and blame members?
![Network planning | [five transport layers and six application layers] knowledge points and examples](/img/4f/31acce51b584bed5ef56b2093c4db3.png)
Network planning | [five transport layers and six application layers] knowledge points and examples

Lumiprobe染料 NHS 酯丨BDP FL NHS 酯研究

左值引用和右值引用

A complete collection of vulnerability scanning tools. Mom doesn't have to worry that I won't find any more vulnerabilities

Lumiprobe 聚乙二醇化和 PEG 接头丨碘-PEG3-酸研究

All the important spark summit features were released here last night (with ultra clear video attached)
随机推荐
maya房子建模
Playwright - scroll bar operation
Openfire在使用MySQL数据库后的中文乱码问题解决
The Commission is so high that everyone can participate in the new programmer's partner plan
Heartbeat 与DRBD 配置过程
Introduction to neural network (Part 1)
[try to hack] windows system account security
QT QStringList用法
NLP skill tree learning route - (I) route overview
杰理之检测灵敏度级别确定【篇】
jfinal中如何使用过滤器监控Druid监听SQL执行?
The newly born robot dog can walk by himself after rolling for an hour. The latest achievement of Wu Enda's first disciple
1. Introduction to generating countermeasures network
All the important spark summit features were released here last night (with ultra clear video attached)
浅谈代码语言的魅力
数据库 OLAP、OLTP是什么?相同和不同?适用场景
Jerry's determination of detection sensitivity level [chapter]
AVL balanced binary tree (I) - concept and C language implementation
Jerry's determination of detection sensitivity level [chapter]
Lumiprobe 改性三磷酸盐丨生物素-11-UTP研究