Js+css realizes the method of inducing the mouse gradient to display the div layer _javascript tips

Source: Internet
Author: User
Tags setinterval

This article illustrates the method of js+css realization of the DIV layer in the sensor mouse gradient display. Share to everyone for your reference. The implementation methods are as follows:

Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
&LT;TITLE&GT;JS+CSS implementation of the induction mouse gradient display div layer </title>
<style>
#tip {
Position:absolute;
left:90px;
width:0px;
height:0px;
Color: #FFF;
font-size:12px;
Background-color: #000;
border:1px solid #DEF;
Filter:alpha (opacity=0);
opacity:0;
z-index:999;
}
</style>
<script type= "Text/javascript" >
<!--
Defines the "Get specified DOM node" function because of its high reuse rate
function $ (d) {return document.getElementById (d);}
Control Div gradually show
var i = 0;
function Change_show () {
var obj = $ ("Tip");
i=i+5; Show Speed gradually
Obj.style.filter = "Alpha (opacity=" + i + ")"; Transparency gradually becomes smaller
obj.style.opacity = i/100; Compatible Firefox
if (i>=100) {
Clearinterval (s);
i=0;
}
}
Control Div gradually disappear
var j = 100;
function Change_hidden () {
var obj = $ ("Tip");
j=j-5; Gradually disappearing speed
Obj.style.filter = "Alpha (opacity=" + j + ")"; Transparency is getting bigger
obj.style.opacity = j/100; Compatible Firefox
if (j<=0) {
Clearinterval (h);
Obj.style.display= "None";
j=100;
}
}
Control Change_show () behavior
var s;
function Show (x) {
if (s) {clearinterval (s);}
$ ("Tip"). style.display= "Block";
s = setinterval (change_show,1);
}
Control Change_hidden () behavior
function hidden (x) {
$ ("Tip"). innerhtml= "";
h = setinterval (change_hidden,1);
}
-->
</script>
<body>
<div id= "Tip" style= "background-color:blue;width:48%;height:48%;" onmouseover= "show (This);" Onmouseout= "Hidden ( this); " >
</div>
<br/>
<br> mouse over here, div layer gradient display <br></body>

I hope this article will help you with your JavaScript programming.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.