当前位置:网站首页>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>边栏推荐
- ASP. Net hosting uploading file message 500 error in IIS
- Two micro service interviews where small companies suffer losses
- About pyqt5 to realize paging function (one window implements different interfaces)
- Three indicators to help you measure the effectiveness of digital transformation
- Top ten popular codeless testing tools
- Analysis on the issue of raising the right of MSSQL in 2021 secondary vocational group network security competition in Shandong Province
- Why should state-owned enterprises accelerate the digital transformation
- Digital trend analysis of B2B e-commerce market mode and trading capacity in electronic components industry
- Ultimate Guide: comprehensive analysis of log analysis architecture of Enterprise Cloud native PAAS platform
- 腾讯云荣获“可信云技术最佳实践-虚拟化”
猜你喜欢

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

How to start cloud native application development

Get the actual name of the method parameter through the parameter
Ultimate Guide: comprehensive analysis of log analysis architecture of Enterprise Cloud native PAAS platform

How MySQL works - Chapter 14

Project Management Guide: tips, strategies and specific practices

微服务系统设计——数据模型与系统架构设计

Mcu-08 interrupt system and external interrupt application

Network security database penetration of secondary vocational group in 2022

微服务系统设计——接口文档管理设计
随机推荐
Application service access configuration parameters
SAP license:sap s/4hana is the answer
Several key points for enterprises to pay attention to digital transformation
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?
Get max value of a bit column - get max value of a bit column
Nine practical guidelines for improving responsive design testing
Selection (030) - what is the output of the following code?
Crmeb multi merchant PC packaging tutorial
Leetcode daily question solution: 717 1-bit and 2-bit characters - reverse order
Digital transformation informatization data planning and technology planning
Data driven decision making: Decision intelligence and design thinking
Redis series (3) - sentry highly available
Analysis on the issue of raising the right of MSSQL in 2021 secondary vocational group network security competition in Shandong Province
Industry Cloud video editing software
25.sql statement differentiation
Palindrome string (two methods)
Eight digit
Ten software development indicators for project managers
Leetcode question 136 [single number]
congratulate! The first dragon lizard community annual outstanding contribution award is announced. Check it now