This article shares the specific code of JavaScript to achieve skin-changing effect for your reference. The specific content is as follows Skin-changing effect: Click on different pictures to change the background of the corresponding page Implementation ideas 1. Define a set of pictures, and assign the background picture path to each src attribute Code Sample<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Skin effect</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { background: url(images/壁纸1.jpg) no-repeat center top; background-size: cover; } .box { overflow: hidden; width: 610px; margin: 100px auto; background-color: #fff; } .box li { width: 25%; height: 100px; list-style: none; float: left; cursor: pointer; border: 1px solid #fff; } img { width: 100%; height: 100%; } </style> </head> <body> <ul class="box"> <li><img src="images/壁纸1.jpg" alt=""></li> <li><img src="images/壁纸2.jpg" alt=""></li> <li><img src="images/壁纸3.jpg" alt=""></li> <li><img src="images/壁纸4.jpg" alt=""></li> </ul> <script> var pics = document.querySelector('.box').querySelectorAll('img'); console.log(pics); for (var i = 0; i < pics.length; i++) { pics[i].onclick = function() { console.log(this.src); document.body.style.backgroundImage = 'url(' + this.src + ')'; } } </script> </body> </html> Page EffectsThe above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: MySQL grouping queries and aggregate functions
>>: Analysis of Apache's common virtual host configuration methods
html <div class="totop" v-show="...
This article example shares the specific code for...
Table of contents 1. Core 1. Get the Dom node 2. ...
Table of contents Overview 1. RangeError 2. Refer...
Table of contents 1. CentOS7+MySQL8.0, yum source...
Preface Index Condition Pushdown (ICP) is a new f...
MySQL encryption and decryption examples Data enc...
Website link: http://strml.net/ By Samuel Reed Ti...
How to center your HTML button itself? This is ea...
Table of contents Business Logic Data table struc...
1. How to represent the current time in MySQL? In...
Although Mac systems come with PHP and Apache, so...
The span tag is often used when making HTML web p...
<br /> Focusing on the three aspects of text...
Currently encountering such a problem My situatio...