当前位置:网站首页>JS clothing photo album case
JS clothing photo album case
2022-06-24 18:35:00 【Brother Mengfan】
One 、 demand
Two 、 case analysis
1、 Event source : It's a small picture li
2、 Event type : Move (onmouseover)
3、 Event handler :
(1) Assign the small image path to the large image path :img.src = this.children[0].src;
(2) add to Red border class :className
3、 ... and 、 The code is as follows
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Clothes photo album </title>
<style>
* {
padding: 0;
margin: 0;
}
ul {
list-style: none;
overflow: hidden;
}
ul li {
float: left;
width: 50px;
height: 50px;
margin-left: 10px;
margin-top: 20px;
border: 2px solid #fff;
}
ul li.active {
border-color: red;
}
ul li img {
width: 46px;
cursor: pointer;
}
</style>
</head>
<body>
<img src="images/1.jpg" id="bigImg">
<ul>
<li><img src="images/1.jpg" class="smallImg"></li>
<li class="active"><img src="images/2.jpg" class="smallImg"></li>
<li><img src="images/3.jpg" class="smallImg"></li>
<li><img src="images/4.jpg" class="smallImg"></li>
<li><img src="images/5.jpg" class="smallImg"></li>
</ul>
<script>
// 1. Get elements
var img = document.querySelector('#bigImg');
var lis = document.querySelectorAll('li');
// Traverse li
for (var i = 0; i < lis.length; i++) {
// Move the mouse to li On
lis[i].onmouseover = function() {
//console.log(this.children[0].src)
// display picture Give the path of the small picture to the path of the large picture
img.src = this.children[0].src;
// Exclusive
for (var j = 0; j < lis.length; j++) {
lis[j].removeAttribute('class');
}
// To current li Add the style
this.className = 'active';
};
}
</script>
</body>
</html>边栏推荐
- EasyCVR国标协议接入的通道,在线通道部分播放异常是什么原因?
- JDBC writes Chinese garbled code to the database
- Analysis on the issue of raising the right of MSSQL in 2021 secondary vocational group network security competition in Shandong Province
- Keep two decimal places
- Selection (031) -cool_ How long can secret be accessed?
- What are the grades of financial products?
- [can you really use es] Introduction to es Basics (I)
- Nacos cluster starts throwing set of SQL_ SELECT_ LIMIT is not support
- Is there a security risk in opening an account online? What to do if the business department opening an account nearby is far away from home. Is there any capital requirement for opening an account?
- Online sequence flow chart making tool
猜你喜欢

Eight recommended microservice testing tools
Business based precipitation component = & gt; manage-table

SAP license: what is ERP supply chain

Overall planning and construction method of digital transformation

如何在 R 中使用 Fisher 的最小显着性差异 (LSD)

Wechat applet development - Implementation of rotation chart

Regression testing strategy for comprehensive quality assurance system

The country has made a move! Launch network security review on HowNet

360 digital released information security trends in January: 120000 fraud risks were captured and users were reminded 2.68 million times

Cloud service selection of enterprises: comparative analysis of SaaS, PAAS and IAAs
随机推荐
13 ways to reduce the cost of cloud computing
Leetcode daily question solution: 717 1-bit and 2-bit characters - reverse order
The country has made a move! Launch network security review on HowNet
Does the wave of layoffs in Chinese enterprises in 2021 need to be "judged" by morality?
ASP. Net hosting uploading file message 500 error in IIS
Flutter dart regular regexp special characters $, () (IV)
How does the chief information security officer discuss network security with the enterprise board of directors
Specification for self test requirements of program developers
Is it safe to open an account online? What should I do?
[untitled]
Project Management Guide: tips, strategies and specific practices
Complete Guide to web application penetration testing
[NLP] 3 papers on how Stanford team builds a better chat AI
视频平台如何将旧数据库导入到新数据库?
2022 network security C module of the secondary vocational group scans the script of the surviving target aircraft (municipal, provincial and national)
High quality defect analysis: let yourself write fewer bugs
Flutter dart regular regexp matches non printing characters \cl\cj\cm\ck
An analysis of the comments on the TV series Douban by procedural apes
Wechat applet to realize stacked rotation
Four security issues of low code and no code development