jquery Animation Special Effects Example Tutorial _jquery

Source: Internet
Author: User

In this paper, the implementation method of jquery animation effects is described in detail in the form of examples. Share for everyone to use for reference. The specific methods are as follows:

1. Self-made folding content block

The content blocks are as follows:

<div class= "module" >
  <div class= "caption" >
    <span> title </span>
    
  </div>
  <div class=" Body ">
    recently," Sports Weekly, reporter Madsching in the Tianjin Sports channel "New Horizons of Sport" program interview, said he was worried about the situation of Evergrande [Weibo], Evergrande's dominance has fallen a lot more than last season, and there is a problem of overlapping positions in foreign aid, which is an acceptable result for travellers away from west Sydney. The program called Evergrande League 3 winning streak wins, Evergrande can not afford to mediocre, Evergrande lost the overwhelming advantage to other teams, the ability to decline is the dominant position of Evergrande has shaken the root.
  </div>
</div> 

Bind the IMG element to a point hit event.

$ (function () {
  $ (' div.caption img '). Click (function () {
 //The parent element of the IMG is found first, then the child element
 var $body = $ (this) for the parent element. Closest (' Div.module '). Find (' div.body ');
 if ($body. Is (': Hidden ')) {
   $body. Show ();
 }. {
   $body. Hide ();
 }
  });


The effect is as shown in the following illustration:

You can also use the toggle method to toggle the display state of an element.

$ (function () {
  $ (' div.caption img '). Click (function () {
 $ (this). Closest (' Div.module '). Find (' Div.body '). Toggle ();
  });


The above is no animation effect, sometimes it will be very abrupt. In fact, the Show,hide,toggle method can have animation effects. Like what:

$ (function () {
  $ (' div.caption img '). Click (function () {
 $ (this). Closest (' Div.module '). Find (' Div.body '). Toggle (' slow ');
  });


Another example:

$ (function () {
  $ (' div.caption img '). Click (function () {
 $ (this). Closest (' Div.module '). Find (' Div.body '). Toggle (' Slow ', function () {
   $ (this). Closest (' Div.module '). Toggleclass (' Rolledup ', $ (a). Is (': Hidden '))
 });
  });
}); 

2. Make elements fade in

FadeIn (speed, callback) fadeout (speed, callback) Fadeto (speed, opacity
, callback)

3. Sliding elements up and down

Slidedown (speed, callback) Slideup (speed, callback)
Slidetoggle (speed, callback)


4. Stop animation

Stop (Clearqueue, gotoend)

5. Create a custom animation

Animate (properties, duration, easing, callback)

$ ('. ClassName '). Animate ({opacity: ' Toggle '}, ' slow ')

If you write an extension function.

$.fn.fadetoggle = function (speed) {return
  this.animate ({opacity: ' Toggle '}, ' slow ');
}

6. Custom Zoom Animation

$ ('. ClassName '). each (the function () {
  $ (this). Animate ({
    width: $). Width () * 2,
    Height: $ (this). Height () * 2
  });


7. Custom Drop Animation

$ ('. ClassName '). each (function () {
  $ (this)
    . CSS ("position", "relative")
    . Animate ({
      opacity:0, Top
      : $ (window). Height ()-$ (this). Height ()-$ (a). Position (). Top
    }, ' Slow ', function () {$ (this). Hide ();
});

8. Custom Scatter Animation

$ ('. ClassName '). each (the function () {
  var position = $ (this). Position ();
  $ (this)
    . css ({
      position: ' absolute ',
      top:position.top,
      left:position.left
    })
    . Animate ({
      opacity: ' Hide ',
      width: $ (this). Width () *5,
      Height: $ (a). Height () *5 top
      : Position.top-($ (this). Height () * 5/2),
      Left:position.left-($ (this). Width () * 5/2)
    }, ' normal ');


9. Animation in the queue

Animation Insert Queue
$ (' img '). Queue (' Chain ', function () {});
$ (' img '). Queue (' Chain ', function () {});
$ (' img '). Queue (' Chain ', function () {});
$ (' img '). Queue (' Chain ', function () {});

$ (' button '). Click (function () {
  $ (' img '). Dequeue (' chain ');//Delete animation in queue
)

cleaequeue (name)// Remove the animation
delay (duration, name)//In all Unassigned queues add a delay for all the animations that are not performed in the queue

It is believed that this article has certain reference value to the jquery program design of everybody.

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.