JS animation effect code 3

Source: Internet
Author: User

Slowly, this time we have achieved expansion in any direction! CopyCode The Code is as follows: <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
<Style type = "text/CSS">
<! --
# Apdiv1 {
Position: absolute;
Left: 300px;
Top: 100px;
Width: 100px;
Height: 100px;
Z-index: 1;
Background-color: # ff00ff;
}
# Apdiv2 {
Position: absolute;
Left: 402px;
Top: 100px;
Width: 100px;
Height: 100px;
Z-index: 2;
Background-color: #00 FFFF;
}
# Apdiv3 {
Position: absolute;
Left: 402px;
Top: 200px;
Width: 100px;
Height: 100px;
Z-index: 3;
Background-color: #99ff00;
}
# Apdiv4 {
Position: absolute;
Left: 300px;
Top: 200px;
Width: 100px;
Height: 100px;
Z-index: 4;
Background-color: # FFFF00;
}
-->
</Style>
</Head>

<Body>
<Div id = "apdiv1"> </div>
<Div id = "apdiv2"> </div>
<Div id = "apdiv3"> </div>
<Div id = "apdiv4"> </div>
</Body>
</Html>
<Script language = "JavaScript" type = "text/JavaScript">
Function $ (PID ){
Return document. getelementbyid (PID );
}

Function JPOs (){

}

JPOs. getabspos = function (pTARGET ){
VaR _ x = 0;
VaR _ y = 0;
While (pTARGET. offsetparent ){
_ X + = pTARGET. offsetleft;
_ Y + = pTARGET. offsettop;
PTARGET = pTARGET. offsetparent;
}
_ X + = pTARGET. offsetleft;
_ Y + = pTARGET. offsettop;

Return {X: _ x, y: _ y };
}

Function janiobj (){
This. OBJ = NULL;
This. interval = NULL;

This. orgpos = NULL;
This.tar getpos = NULL;

This. orgsize = {W: 50, Y: 50}; // initial length and width
This.tar getsize = {W: 100, Y: 100}; // The target length and width.
This. Step = {X: 10, Y: 10}; // step X: X direction Y: Y direction
This. Alpha = {s: 10, E: 90, T: 10}; // transparency, initial S, end e, step t
}

Function Jani (){
VaR self = this;
VaR aniobjs = {};

VaR getcurrentstyleproperty = function (pobj, pproperty ){
Try {
If (pobj. currentstyle)
Return eval ("pobj. currentstyle." + pproperty );
Else
Return document. defaultview. getcomputedstyle (pobj, ""). getpropertyvalue (pproperty );
} Catch (e ){
Alert (E );
}
}

This. popup = function (pdiv, porgsize, ptargetsize, pstep, palpha ){

VaR aniobj = new janiobj ();
Aniobjs [pdiv] = aniobj;

With (aniobj ){
OBJ = $ (pdiv );
Orgpos = JPOs. getabspos (OBJ );
Orgsize = porgsize;
Targetsize = ptargetsize;
Step = pstep;
Alpha = palpha;

With (obj. Style ){
Overflow = "hidden ";
Position = "absolute ";
Width = porgsize. W + "PX ";
Height = porgsize. H + "PX ";
Left = orgpos. x + "PX ";
Top = orgpos. Y + "PX ";
If (document. All ){
Filter = "alpha (opacity =" + palpha. S + ")";
} Else
Opacity = palpha. S/100;
}
}

Aniobj. interval = setinterval ("popup _ ('" + pdiv + "')", 10 );
}

Popup _ = function (pdivid ){

Pobj = aniobjs [pdivid];

VaR W = parseint (pobj. obj. style. width );
VaR H = parseint (pobj. obj. style. Height );

If (W> = math.abs(pobj.tar getsize. W) & H> = math.abs(pobj.tar getsize. H )){
Clearinterval (pobj. interval );
If (document. All)
Pobj. obj. style. Filter = "alpha (opacity =" + pobj. Alpha. e + ")";
Else
Pobj. obj. style. Opacity = pobj. Alpha. E/100;

Delete aniobjs [pobj. obj. ID];
} Else {
If (W <math.abs(pobj.tar getsize. W ))
W + = pobj. Step. X;

If (H <math.abs(pobj.tar getsize. h ))
H + = pobj. Step. Y;

If (document. All ){
VaR pattern =/opacity = (\ D {1, 3 })/;
VaR result = pattern.exe C (pobj. obj. style. Filter );
If (result! = NULL ){
If (result [1] <pobj. Alpha. e)
Pobj. obj. style. Filter = "alpha (opacity =" + (result [1] + pobj. Alpha. t) + ")"
Else
Pobj. obj. style. Filter = "alpha (opacity =" + pobj. Alpha. e + ")";
}
} Else {
If (pobj. obj. style. Opacity <pobj. Alpha. E/100 ){
Pobj. obj. style. Opacity = parsefloat (pobj. obj. style. opacity) + pobj. Alpha. T/100;
} Else
Pobj. obj. style. Opacity = pobj. Alpha. E/100;
}
}

Pobj. obj. style. width = W + "PX ";
Pobj. obj. style. Height = H + "PX ";

If(pobj.tar getsize. W <0 ){
VaR vleft = parseint (getcurrentstyleproperty (pobj. OBJ, "Left "));
Vleft = isnan (vleft )? 0: vleft;
Pobj. obj. style. Left = vleft-pobj. Step. x + "PX ";
}

If(pobj.tar getsize. H <0 ){
VaR vtop = parseint (getcurrentstyleproperty (pobj. OBJ, "TOP "));
Vtop = isnan (vtop )? 0: vtop;
Pobj. obj. style. Top = vtop-pobj. Step. Y + "PX ";
}
}
}

VaR ani = new Jani ();
Ani. Popup (
"Apdiv1 ",
{W: 50, H: 50}, // initial length and width
{W: 200, H: 200}, // target length and width
{X: 8, Y: 8}, // step size
{S: 10, E: 80, T: 10} // transparency start, end, step size
);

Ani. Popup (
"Apdiv2 ",
{W: 50, H: 50}, // initial length and width
{W:-200, H: 200}, // target length and width
{X: 8, Y: 8}, // step size
{S: 10, E: 40, T: 2} // transparency start, end, step size
);

Ani. Popup (
"Apdiv3 ",
{W: 50, H: 50}, // initial length and width
{W:-200, H:-200}, // target length and width
{X: 8, Y: 8}, // step size
{S: 10, E: 40, T: 10} // transparency start, end, step size
);

Ani. popup (
"apdiv4",
{W: 50, H: 50}, // initial length and width
{W: 200, H:-200 }, // target length and width
{X: 8, Y: 8}, // step
{s: 10, E: 50, t: 10} // opacity start, end, step
);

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.