JS Motion frame _ including picture fade effect _javascript skill

Source: Internet
Author: User

Copy Code code as follows:

<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>
<font face= "Verdana, Geneva, Sans-serif" ></font>
<style type= "Text/css" >
#div1 {width:100px;height:100px;background: #ccc;p osition:absolute;top:0px;left:0px;}
#div2 {width:100px;height:100px;background: #ccc;p osition:absolute;left:0px;top:110px;}
#div3 {width:100px;height:100px;background:red;position:absolute;left:220px;top:0px;filter:alpha (opacity:30); o pacity:0.3;}
#div4 {width:100px;height:100px;background:red;position:absolute;left:330px;top:0px;filter:alpha (opacity:30); o pacity:0.3;}
#div5 {width:100px;height:100px;background:red;position:absolute;left:440px;top:0px;filter:alpha (opacity:30); o pacity:0.3;}
</style>
<script type= "Text/javascript" >
Window.onload=function ()
{
Odiv1=document.getelementbyid ("Div1");
Odiv2=document.getelementbyid ("Div2");
Odiv3=document.getelementbyid ("Div3");
Odiv4=document.getelementbyid ("Div4");
Odiv5=document.getelementbyid ("div5");

Odiv1.onmouseover=function () {
Move (ODIV1, "width", 200);
Alert (GetStyle (ODIV1, "width"));
}
Odiv1.onmouseout=function () {
Move (ODIV1, "width", 100);
}
Odiv2.onmouseover=function () {
Move (ODiv2, "height", 200);
}
Odiv2.onmouseout=function () {
Move (ODiv2, "height", 100);
}
Odiv3.onmouseover=function () {
Move (ODiv3, "opacity", 100);
}
Odiv3.onmouseout=function () {
Move (ODiv3, "opacity", 30);
}

Odiv4.onmouseover=function () {
Move (ODIV4, "opacity", 100);
}
Odiv4.onmouseout=function () {
Move (ODIV4, "opacity", 30);
}
Odiv5.onmouseover=function () {
Move (ODIV5, "opacity", 100);
}
Odiv5.onmouseout=function () {
Move (ODIV5, "opacity", 30);
}


}
Get style between rows
function GetStyle (obj,attr)//getstyle non-row property result value is ***PX
{if (Obj.currentstyle)
{
return obj.currentstyle[attr];
}
else{
Return getComputedStyle (Obj,false) [attr];
}
}
Multi-Object different motion frame
function Move (obj,attr,itarget)
{
Clearinterval (Obj.timer);
Obj.timer=setinterval (function () {
if (attr== "opacity")
{Cur=parsefloat (GetStyle (obj,attr)) *100;
Speed= (itarget-cur)/10;
Speed=speed>0? Math.ceil (Speed): Math.floor (speed);

if (cur==itarget)
{
Clearinterval (Obj.timer);
}else
{cur+=speed;
obj.style.opacity=cur/100;
Obj.style.filter= "Alpha (opacity:" +cur+ ")";
}
}
Else
{
Cur=parseint (GetStyle (obj,attr));
Speed= (itarget-cur)/10; Parseint the value obtained is converted to a number
Speed=speed>0?    Math.ceil (Speed): Math.floor (speed); Downward, up positive

if (cur==itarget)
{
Clearinterval (Obj.timer);
}else
{
obj.style[attr]=cur+speed+ "px";
}
}

},30)
}
</script>

<body>
<div id= "Div1" > Widening </div>
<div id= "Div2" > High </div>
<div id= "Div3" ></div>
<div id= "Div4" ></div>
<div id= "DIV5" ></div>
</body>

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.