_javascript techniques for controlling layers in JavaScript
Source: Internet
Author: User
The development of the layer in the practical application of more important, such as floating ads, and so on, I have a brief discussion here.
1. Show or hide the control layer
Both methods are in fact controlled style.
Method One: Control Display Properties
<script language= "JavaScript" >
function Show (status)
{
document.getElementById ("Div1"). style.display = status;
}
</script>
<div id= "Div1" style= "LEFT:10PX;TOP:200PX;WIDTH:250;HEIGHT:100;Z-INDEX:2;" >
This is a layer, can see, hehe.
</div>
<a href=# onclick= "Show (' Block ');" > Show </a>
<a href=# onclick= "Show (' None ')" > Close </a>
Method II Control Visibility properties
<script language= "JavaScript" >
function Show (status)
{
document.getElementById ("Div1"). style.visibility = status;
}
<div id= "Div1" style= "Left:10px;top:200px;width:250;height:100;z-index:2;visibility=hideen;" >
This is a layer, can see, hehe.
</div>
<a href=# onclick= "show (' visible);" > Show </a>
<a href=# onclick= "Show (' Hidden ')" > Close </a>
If you want the control layer to shut down regularly, you can add:
function Settimestart ()
10 {
One window.settimeout (hiddentips,4000);
12}^
</script>
The code above is to use the SetTimeout method to control the shutdown layer after 4 seconds.
2. Control layer of movement, similar to floating advertising
The main thing is to move through the values of the top and left properties in the control layer style, by randomly generating different values that look like they are in motion.
<script language= "JavaScript" >
var a=200, b=100;
var c=0.1;
var d=5;
var t=0;
function float_1 ()
{
var random1 = 100*math.random ();
var random2 = 100*math.random ();
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service