当前位置:网站首页>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>边栏推荐
- congratulate! The first dragon lizard community annual outstanding contribution award is announced. Check it now
- You don't know about this inspection platform. It's a big loss!
- Flutter dart regular regexp matches non printing characters \cl\cj\cm\ck
- What is decision intelligence?
- Three layer switching experiment
- Selection (030) - what is the output of the following code?
- 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?
- C language - structure II
- Four security issues of low code and no code development
- Seven strategies for successfully integrating digital transformation
猜你喜欢

Number of occurrences of numbers in the array (medium difficulty)
[North Asia data recovery]_ mdb_ catalog. Mongodb database data recovery case in case of WT file corruption

Wechat applet development - Implementation of rotation chart

Mariana Trench, Facebook's open source code analysis tool

SAP license: SAP s/4 Hana module function introduction
Paper sharing | self supervised learning paper jointly released by Yann Lecun and read by engineers
[golang] leetcode intermediate - jumping game & different paths

Analysis on the issue of raising the right of MSSQL in 2021 secondary vocational group network security competition in Shandong Province

Wechat applet to realize stacked rotation

13 skills necessary for a competent QA Manager
随机推荐
Gateway solves cross domain access
Leetcode weekly buckle 281
[NLP] 3 papers on how Stanford team builds a better chat AI
next_ Permutation full permutation function
Get the actual name of the method parameter through the parameter
717.1-bit and 2-bit characters [sliding window]
微服务系统设计——接口文档管理设计
Leetcode question 136 [single number]
SAP license:sap s/4hana is the answer
High quality defect analysis: let yourself write fewer bugs
腾讯云TCS:面向应用的一站式PaaS 平台
解决执行MapReduce程序控制台没有日志信息WARN Please initialize the log4j system properly
Recommend 14 commonly used test development tools
Six configuration management tools that administrators must know
Number of occurrences of numbers in the array (medium difficulty)
Seven strategies for successfully integrating digital transformation
Project Management Guide: tips, strategies and specific practices
2022 network security C module of the secondary vocational group scans the script of the surviving target aircraft (municipal, provincial and national)
[can you really use es] Introduction to es Basics (I)
110. balanced binary tree