Implementation of the caching effect by jquery animate method

Source: Internet
Author: User

Animate () method

Change the height of the "div" element:

The code is as follows Copy Code

$ (". Btn1"). Click (function () {
$ ("#box"). Animate ({height: "300px"});
});

Full instance

The code is as follows Copy Code

<script type= "Text/javascript" src= "/jquery.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function ()
{
$ (". Btn1"). Click (function () {
$ ("#box"). Animate ({height: "300px"});
});
$ (". Btn2"). Click (function () {
$ ("#box"). Animate ({height: "100px"});
});
});
</script>
<body>
<div id= "box" style= "background: #98bf21; height:100px;width:100px;margin:6px;" >
</div>
<button class= "BTN1" >Animate</button>
<button class= "BTN2" >Reset</button>
</body>


An instance (animation function and animation queue)

The code is as follows Copy Code

CSS section:

<style type= "Text/css" >

*{margin:0;padding:0;}

UL li{List-style:none;}

img {border:0 none;}

body {padding:100px;}

Input[name= ' show ']{position:fixed;right:50%; top:50px;}

Input[name= ' Hide ']{position:fixed;right:40% top:50px;}

div.test{width:100px;position:relative;border:1px blue Solid;}

</style>

HTML section:

<input name= "Show" type= "button" value= "click Test"/>

<div> Fill in Content </div>

jquery section:

<script type= "Text/javascript" >

$ (function () {

$ (' div.test '). CSS ("opacity", "0.5");

$ (' input '). Focus ()

. Click (function () {

$ (' div.test '). Animate ({left: ' 400px ', Height: ' 100px '},200)

. Animate ({top: ' 200px ',},200)

. Animate ({left:0},200)

. Animate ({top:0},{duration:200,step:cb,queue:true})//change the queue value to false so that the animation is not added to the animation queue, that is, the animation is not performed in the default order; Step is the callback function of animation function

})

Function CB () {

$ (this). CSS ({

border: ' 2px red solid ',

Opacity:1

})

} })

</script>

This effect is very cow, if the use of JS incompatible does not say still very troublesome, with its cache effect of 123 to fix.

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.