Home > Web Front-end > JS Tutorial > Controlling layers in javascript_javascript skills

Controlling layers in javascript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 19:22:12
Original
1051 people have browsed it

The development of layers is more important in practical applications, such as floating advertisements, etc. I will briefly discuss it here.

1. Control the display or hiding of layers

Both methods actually control the style.

Method 1: Control the display attribute





This is a layer, can you see it, haha.

Show
Close



Method 2 Control the visibility attribute




Above The code uses the setTimeout method to control the layer to close after 4 seconds.


2. Control the movement of the layer, similar to floating ads

Mainly by controlling the values ​​of the top and left attributes in the layer style, by randomly generating different values, It looks like it's in motion.







Let me move.



<script> <BR>function show(status) <BR>{ <BR> document.getElementById("div1").style.display = status; <BR>} <br><br></script><script> <BR>function show(status) <BR>{ <BR> document.getElementById("div1").style.visibility = status; <BR>} <br><br><div id="div1" style="left:10px;top:200px;width:250;height:100;z-index:2;visibility=hideen;"> <BR> 这是一层,能看见吗,呵呵. <BR> <BR><a href=# onClick="show('visible);">显示 <BR><a href=# onClick="show('hidden')">关闭 <br><br><BR>如果要控制层定时关闭的话,可以加上: <br><br>function setTimeStart() <BR> 10 { <BR> 11 window.setTimeout(hiddenTips,4000); <BR> 12 }^ <BR></script> is called through the setTimeout method and runs every few seconds to achieve the purpose of continuous movement. <script> <BR>var a=200, b=100; <BR>var c=0.1; <BR>var d=5; <BR>var t=0; <br><br>function float_1() <BR>{ <BR> var random1 = 100*Math.random(); <BR> var random2 = 100*Math.random(); <br><br> var float_1 = document.all ? document.all.float_1.style : document.float_1; <BR> float_1.left = Math.round(a*Math.cos(t)*Math.cos(t/d)+a)+random1; <BR> float_1.top = Math.round(b*Math.sin(t)+b)+random2; <br><br> t+=c; <br><br> setTimeout("float_1()", 500); <br><br>} <BR></script>
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