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.
Function: click the button on the top of the page to switch between pages. You can also click the page at the bottom of the page to switch between the shrinking and expanding statuses.
Initial effect Preview
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 expstatus = $ div. data ("expstatus ");
If (! Expstatus ){
// Not expanded
$ Div. data ("expstatus", "yes ");
}
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 ","");
});
//
Var expstatus1 = $ page1.data ("expstatus ");
If (expstatus1 ){
$ Page1.data ("expstatus", null );
}
Var expstatus2 = $ page2.data ("expstatus ");
If (expstatus2 ){
$ Page2.data ("expstatus", null );
}
Var expstatus3 = $ page3.data ("expstatus ");
If (expstatus3 ){
$ Page3.data ("expstatus", null );
}
Var expstatus4 = $ page4.data ("expstatus ");
If (expstatus4 ){
$ Page4.data ("expstatus", null );
}
If (e ){
E. stopPropagation ();
Return false;
} Else {
Return true;
}
};
//
$ ("# 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 );
});
// New
$ (". Pages"). unbind ("click touchstart"). bind ("click touchstart", function (e ){
//
Var $ this = $ (this );
Var expstatus = $ this. data ("expstatus ");
If (! Expstatus ){
// Not expanded
//
Return increase ($ this, e );
} Else {
Return resize (e );
}
});
//
$ ("Body"). click (function (e ){
// Remove all
Return resize (null );
});
});
</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>