Home > Web Front-end > JS Tutorial > JS method to implement three layers of overlapping clicks to switch between each other_javascript skills

JS method to implement three layers of overlapping clicks to switch between each other_javascript skills

WBOY
Release: 2016-05-16 15:37:18
Original
1168 people have browsed it

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>

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template