The specific code for implementing skinning with native JavaScript is for your reference. The specific content is as follows principle Through the click event, get the information of the clicked image and change the path of the HTML background image CSS Styles <style> body{ margin:0; padding:0; background:url(img/1.jpg) no-repeat; background-size:100% 100%; } #box{ width:100%; height:130px; background:#999999; } #box ul{ margin:0; padding:0; list-style:none; } #box ul li li,#box ul li img{ width:180px; height:120px; float:left; margin:5px 60px; } </style> HTML source code <body id="Body"> <div id="box"> <ul> <li><img src="img/1.jpg" /></li> <li><img src="img/2.jpg" /></li> <li><img src="img/3.jpg" /></li> <li><img src="img/4.jpg" /></li> <li><img src="img/5.jpg" /></li> </ul> </div> </body> JavaScript source code <script> var oBody = document.getElementById('Body'); var oImg = document.getElementsByTagName('img'); for(var i=0;i<oImg.length;i++) { var oImgA=oImg[i]; oImgA.index=i+1; oImgA.onclick=function(){ //console.log(this); oBody.style.background='url(img/'+this.index+'.jpg) no-repeat'; oBody.style.backgroundSize = '100% 100%'; }; } </script> Rendering Click to switch Source code <!DOCTYPE> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Skin Change</title> <style> body{ margin:0; padding:0; background:url(img/1.jpg) no-repeat; background-size:100% 100%; } #box{ width:100%; height:130px; background:#999999; } #box ul{ margin:0; padding:0; list-style:none; } #box ul li li,#box ul li img{ width:180px; height:120px; float:left; margin:5px 60px; } </style> </head> <body id="Body"> <div id="box"> <ul> <li><img src="img/1.jpg" /></li> <li><img src="img/2.jpg" /></li> <li><img src="img/3.jpg" /></li> <li><img src="img/4.jpg" /></li> <li><img src="img/5.jpg" /></li> </ul> </div> </body> </html> <script> var oBody = document.getElementById('Body'); var oImg = document.getElementsByTagName('img'); for(var i=0;i<oImg.length;i++) { var oImgA=oImg[i]; oImgA.index=i+1; oImgA.onclick=function(){ //console.log(this); oBody.style.background='url(img/'+this.index+'.jpg) no-repeat'; oBody.style.backgroundSize = '100% 100%'; }; } </script> The 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:
|
<<: Nginx learning how to build a file hotlink protection service example
>>: Perfect solution to the problem of connection failure after MySQL client authorization
Table of contents Preface 1. Why do cross-domain ...
1. The ENV instruction in the Dockerfile is used ...
Preface The blogger uses the idea IDE. Because th...
A simple MySQL full backup script that backs up t...
1. Create a new configuration file docker_nginx.c...
This article mainly introduces the sample code of...
Table of contents 1. Add users 2. Change the user...
Table of contents 1. Install Docker 2. Install Gi...
Since PHP7 came out, as a fan of the latest versi...
01. Overview Absolute paths and relative paths ar...
This article describes the MySQL multi-table join...
1. Command Introduction The date command is used ...
This article mainly introduces the sample code of...
In order to facilitate the storage and access of ...
MySQL database too many connections This error ob...