Learning JQuery-12

Source: Internet
Author: User

3. Create a Custom Animation

We arrange "display/hide" in sequence as an animation!

JQuery provides a powerful method: animate ()

Today we will focus on the effects achieved when two parameters are used.

.animate({properties},duration);
Before using it, let's review: box-model



Because there are a lot of settings in the properties of. animate (). <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Margin + margin = "brush: java;"> 1) margin) borderLeft3) margin) borderRight5) margin) borderSpacing7) borderTop8) margin) borderWidth10) bottom11 margin) left13) marginBottom14) marginLeft15) marginRight16) marginTop17) paddingBottom18) paddingLeft19) paddingRight20) paddingTop21) position22) right23) top
There are also three frequently used attributes: height, width, and opacity. Most of these three attributes use the "toggle" value to achieve the animation effect.

The second parameter is the period set (within how long it took to complete), in milliseconds (MS ).


When we hide the content, the "read more" link is displayed;

However, when we display the content, the "read less" link is displayed;

Js Code

    var $firstPara = $('p').eq(1);$firstPara.hide();$('a.more').click(function(e) {        e.preventDefault();$firstPara.animate({height: 'toggle'}, 500);var $link = $(this);if ($link.text() == 'read more') {$link.text('read less');}else {$link.text('read more');}    });
Click "read more" (the image in the first row is displayed)

Effect upon completion

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 less

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.

Click "read less" (the image of the first row is not hidden)


Effect upon completion

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.

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.


We added the "Blur" and "font" attributes.

Js Code

$firstPara.animate({height: 'toggle', opacity: 'toggle', fontSize: '16px'}, 500);
Effect 1 (click "read more "):

P-3 displays the second row

Effect 2 (click "read less "):


The P-4 does not hide the second line


Appendix:

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


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


Chpater04-3.js

$(document).ready(function() {    var $firstPara = $('p').eq(1);$firstPara.hide();$('a.more').click(function(e) {        e.preventDefault();$firstPara.animate({height: 'toggle', opacity: 'toggle', fontSize: '16px'}, 2000);var $link = $(this);if ($link.text() == 'read more') {$link.text('read less');}else {$link.text('read more');}    });});


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.