Note that this code can be used only when jquery js files are used. Therefore, you can download a jquery file first and pay attention to the call path.
Code:
Copy codeThe 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>
<Title> jQuery animation basics </title>
<Script type = "text/javascript" src = ".../js/jquery-1.2.6.js"> </script>
<Style type = "text/css">
. TheImage {
Position: relative;
Background: Green;
Width: 100px;
}
</Style>
<Script type = "text/javascript">
$ (Function (){
$ ("# BtnShow"). click (function (){
// $ ("# Block"). show (1000); // No animation effect if no parameters exist
// $ ("# Block"). fadeIn ("slow"); // display or hide based on transparency
$ ("# Block"). slideDown (); // pull down. Only change height
});
$ ("# BtnHide"). click (function (){
// $ ("# Block"). hide ("normal"); // slow, normal, fast
// $ ("# Block"). fadeOut (5000 );
$ ("# Block"). slideUp ();
});
// Custom Animation
$ ("# BtnImage"). click (function (){
$ ("# ImageDiv"). animate (
// I
// The location to be moved. The location here is relative to the original location.
// Top: the distance between the top and the original position. If you do not understand it, the result is downward.
// {Left: "400px", top: "100px "},
// 3000
// II
{Left: "+ = 50", width: "300px", height: "200px"}, // change the width and height while changing the position
3000
);
});
// Execute two animations at the same time, finish one, and then execute the other.
$ ("# BtnImage"). click (function (){
$ ("# ImageDiv"). animate (
{Left: "100px", width: "30px", height: "20px "},
3000,
Function () {alert ('callback function');} // function to be executed after the animation ends
);
});
});
</Script>
</Head>
<Body>
<Div>
<Button id = "btnShow"> Show </button>
<Button id = "btnHide"> Hide </button>
<Div id = "block" style = "background: #369; width: 150px; height: 100px;"> Hello! </Div>
<Button id = "btnImage"> moveImage </button>
<Div id = "imageDiv" class = "theImage"> image </div>
<Div> hi </div>
</Div>
</Body>
</Html>