The example in this article describes the method of using JS to switch between three layers by overlapping clicks. Share it with everyone for your reference. The details are as follows:
This effect implements three or more overlapping layers, which overlap according to certain rules. When you click on any layer with the mouse, the layer is displayed at the top, and multiple layers are switched alternately. The code is simple and you can learn at the same time. CSS is also a good reference example. The function of this example requires JavaScript code.
The screenshot of the running effect is as follows:
The online demo address is as follows:
http://demo.jb51.net/js/2015/js-3ccd-tab-click-cha-style-codes/
The specific code is as follows:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>三个或多个层重叠实现互相切换</title> </head> <body> <div id="aaa" style="position:absolute;left:100px;top:100px;width:100px;height:100px;background-color:#ddeeff;z-index:1;" onclick="moveUp(this.id)"></div> <div id="bbb" style="position:absolute;left:150px;top:130px;width:100px;height:100px;background-color:#eeffdd;z-index:2;" onclick="moveUp(this.id)"></div> <div id="ccc" style="position:absolute;left:200px;top:160px;width:100px;height:100px;background-color:#ffddee;z-index:3;" onclick="moveUp(this.id)"></div> <script type="text/javascript"> var divNo = document.getElementsByTagName("div").length; function moveUp(id) { divNo++; var box = document.getElementById(id); box.style.zIndex=divNo; } </script> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming.