Today, I helped my friends write some code and thought it was written. After several versions, I was a little satisfied, so I posted it.
All of them are dead. Because the requirement only has four elements. If you want to use the CSS class for processing, you need to use the CSS3 animation.
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Title> CSS + jQuery animation effect </title>
<Meta name = "Generator" content = "EditPlus">
<Meta name = "Author" content = "tie an">
<Style>
Body {
Z-index: 0;
Width: 100%;
Min-height: 400px;
}
. Pages {
Position: absolute;
}
. Current {
Position: absolute;
Z-index: 12! Important;
Left: 0px! Important;
}
. Page1 {
Background-color: # a5cfff;
Z-index: 1;
Width: 300px;
Height: 280px;
Top: 100px;
Left: 0px;
}
. Page2 {
Background-color: # b1ca54;
Z-index: 2;
Width: 250px;
Height: 270px;
Top: 160px;
Left: 0px;
}
. Page3 {
Background-color: # c2c6c9;
Z-index: 3;
Width: 200px;
Height: 260px;
Top: 220px;
Left: 0px;
}
. Page4 {
Background-color: # ef9e9c;
Z-index: 4;
Width: 150px;
Height: 250px;
Top: 250px;
Left: 0px;
}
</Style>
<Script type = "text/javascript" src = "http://code.jquery.com/jquery-1.9.1.min.js"> </script>
<Script>
$ (Function (){
// Growth
Function increase ($ div, e ){
Var style = $ div. attr ("style ");
$ Div. addClass ("current"). attr ("styleold", style );
//
$ Div. stop ();
$ Div. animate ({
Opacity: 0.9,
Width: "400px ",
Height: "400px ",
Top: "100px ",
Left: "0px"
}, 600)
. Animate ({
Opacity: 1.0
}, 30 );
E. stopPropagation ();
Return false;
};
// Restore
Function resize (e ){
// Remove all
Var $ page1 = $ (". current. page1 ");
$ Page1.stop ();
$ Page1.animate ({
Opacity: 1.0,
Width: "300px ",
Height: "280px ",
Top: "100px ",
Left: "0px"
},600, null, function (){
$ Page1.removeClass ("current"). attr ("style ","");
});
Var $ page2 = $ (". current. page2 ");
$ Page2.stop ();
$ Page2.animate ({
Opacity: 1.0,
Width: "250px ",
Height: "270px ",
Top: "160px ",
Left: "0px"
},600, null, function (){
$ Page2.removeClass ("current"). attr ("style ","");
});
Var $ page3 = $ (". current. page3 ");
$ Page3.stop ();
$ Page3.animate ({
Opacity: 1.0,
Width: "200px ",
Height: "260px ",
Top: "220px ",
Left: "0px"
},600, null, function (){
$ Page3.removeClass ("current"). attr ("style ","");
});
Var $ page4 = $ (". current. page4 ");
$ Page4.stop ();
$ Page4.animate ({
Opacity: 1.0,
Width: "150px ",
Height: "250px ",
Top: "250px ",
Left: "0px"
},600, null, function (){
$ Page4.removeClass ("current"). attr ("style ","");
});
E. stopPropagation ();
Return false;
};
//
$ ("# Button1"). unbind ("mouseover"). bind ("mouseover", function (e ){
//
Var $ page1 = $ (". page1 ");
// Add a specific
Return increase ($ page1, e );
}). Unbind ("mouseout"). bind ("mouseout", function (e ){
Return resize (e );
});
//
$ ("# Button2"). unbind ("mouseover"). bind ("mouseover", function (e ){
//
Var $ page2 = $ (". page2 ");
// Add a specific
Return increase ($ page2, e );
}). Unbind ("mouseout"). bind ("mouseout", function (e ){
Return resize (e );
});
//
$ ("# Button3"). unbind ("mouseover"). bind ("mouseover", function (e ){
//
Var $ page3 = $ (". page3 ");
// Add a specific
Return increase ($ page3, e );
}). Unbind ("mouseout"). bind ("mouseout", function (e ){
Return resize (e );
});
//
$ ("# Button4"). unbind ("mouseover"). bind ("mouseover", function (e ){
//
Var $ page4 = $ (". page4 ");
// Add a specific
Return increase ($ page4, e );
}). Unbind ("mouseout"). bind ("mouseout", function (e ){
Return resize (e );
});
//
$ (". Pages"). unbind ("mouseover"). bind ("mouseover", function (e ){
//
Var $ this = $ (this );
// Add a specific
Return increase ($ this, e );
}). Unbind ("mouseout"). bind ("mouseout", function (e ){
// Remove all
Return resize (e );
});
//
$ ("Body"). click (function (e ){
// Remove all
Return resize (e );
});
});
</Script>
</Head>
<Body>
<Div class = "pages page1"> page1 </div>
<Div class = "pages page2"> page2 </div>
<Div class = "pages page3"> page3 </div>
<Div class = "pages page4"> page4 </div>
<Div style = "background-color: # a5cfff;">
<Button id = "button1"> page 1 </button>
<Button id = "button2"> page 2nd </button>
<Button id = "button3"> page 3rd </button>
<Button id = "button4"> page 4th </button>
</Div>
</Body>
</Html>