Learning JQuery-13

Source: Internet
Author: User

4. effect queue equivalent to animation

We have used the animate () method in the previous section.

The following is an example:

Js Code

    $('div.label').click(function(e) {        var paraWidth = $('div.speech p').outerWidth();var $switcher = $(this).parent();var switcherWidth = $switcher.outerWidth();$switcher.css({postion: 'relative'}).animate({left: paraWidth - switcherWidth}, 'slow').animate({height: '+=20px'}, 'slow').animate({borderWidth: '5px'}, 'slow');    });
The implementation result is as follows:

Abraham Lincoln's Gettysburg AddressText Size Default Bigger Smaller

Fourscore and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal.

Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. we are met on a great battlefield of that war. we have come to dedicate a portion of that field as a final resting-place for those who here gave their lives that the nation might live. it is altogether fitting and proper that we shoshould do this. but, in a larger sense, we cannot dedicate, we cannot consecrate, we cannot hallow, this ground.

Read more

The brave men, living and dead, who struggled here have consecrated it, far above our poor power to add or detract. the world will little note, nor long remember, what we say here, but it can never forget what they did here. it is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced.

It is rather for us to be here dedicated to the great task remaining before us-that from these honored dead we take increased injection to that cause for which they gave the last full measure of injection- that we here highly resolve that these dead shall not have died in vain-that this nation, under God, shall have a new birth of freedom and that government of the people, by the people, for the people, shall not perish from the earth.


Of course, we can also write as follows:

.animate({left: paraWidth - switcherWidth, height: '+=20px', borderWidth: '5px'}, 'slow');
When we execute the above Code, we will find a choppy phenomenon. How can we deal with it?

At this time, we need to use "effect chain" (a series of effect methods ).

One of the methods is not introduced: fadeTo ()

Duration: reaction time (MS ); <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + release/release + sLrPC9wPgo8cD48cHJlIGNsYXNzPQ = "brush: java;">. fadeTo ('fast ', 0.5 ). animate ({left: paraWidth-switcherWidth, height: '+ = 20px'}, 'low '). fadeTo ('low', 1.0 ). slideUp ('low '). animate ({borderWidth: '5px '}, 50 ). slideDown ('low ');
We want two "animate" to be changed to one. Is there any way to implement it?

This requires the queue method!

Js Code

.fadeTo('fast', 0.5).animate({left: paraWidth - switcherWidth, height: '+=20px'}, {duration: 'slow', querue: false}).fadeTo('slow', 1.0).slideUp('slow').queue(function(next) {$switcher.css({borderWidth: '5px'});next();}).slideDown('slow');

Appendix:

Chapter4-2.html (see learning JQuery-11)


Chapter04.css (see learning JQuery-11 for details)


Chapter04-4.js

$(document).ready(function() {    $('div.label').click(function(e) {        var paraWidth = $('div.speech p').outerWidth();var $switcher = $(this).parent();var switcherWidth = $switcher.outerWidth();$switcher.css({postion: 'relative'}).fadeTo('fast', 0.5).animate({left: paraWidth - switcherWidth, height: '+=20px'}, {duration: 'slow', querue: false}).fadeTo('slow', 1.0).slideUp('slow').queue(function(next) {$switcher.css({borderWidth: '5px'});next();}).slideDown('slow');    });});

Related Article

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.