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
RedHat6.5 installation MySQL5.7 tutorial sharing,...
The installation tutorial of mysql5.7.17 is share...
This article will examine the ES6 for ... of loop...
Exposing network ports In fact, there are two par...
MySQL installation is divided into installation v...
The previous article was a simple review of the B...
This story starts with an unexpected discovery tod...
Achieve results The code is as follows html <t...
Table of contents Union query 1. Query the ID and...
1. Windows Server 2019 Installation Install Windo...
1. Source of the problem A friend @水米田 asked me a...
In order to handle a large number of concurrent v...
There are various environmental and configuration...
Table of contents 1. Software Package 2. Install ...
my.cnf is the configuration file loaded when MySQ...