search
HomeWeb Front-endJS TutorialIn-depth learning of jQuery Animate (1)

In-depth learning of jQuery Animate (1)

Nov 13, 2018 pm 02:17 PM
animatejquery

The content of this article is about in-depth learning of Animate in jQuery (1), so that everyone can further understand the usage of animate in jQuery. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

How much do you know about the usage of animate in jQuery? If it is just a simple move of position, show and hide, oh! Oh my gosh you are wasting resources! Because animate is so powerful, you can use it in many unexpected ways! Let’s study it together. [Related video tutorial recommendations: jQuery Tutorial]

First, you need to understand the detailed usage of animate in jQuery API.

animate: Returns jQuery object

animate( properties [, duration ] [, easing ] [, complete ] )

Description: Perform custom animation based on a set of CSS properties.

1. animate( properties [, duration ] [, easing ] [, complete ] )

1. Properties

Type: PlainObject

An object of CSS properties and values. The animation will move according to this group of objects.

2. Duration (default: 400)

Type: Number or String

A string or number determines how long the animation will run. (Default value: "normal", string "slow", "normal", or "fast" or a millisecond value indicating the animation duration (such as: 1000))

3. easing (default: swing)

Type: String

A string indicating which easing function to use for the transition. (jQuery itself provides "linear" and "swing")

4. complete

Type: Function()

Function executed when the animation is completed.

2. animate( properties, options )

1. Properties

Type: PlainObject

An object of CSS properties and values. The animation will move according to this group of objects.

2, options

Type: PlainObject

A set of values ​​containing animation options. Supported options:

1), duration (default: 400)

Type: Number or String

A string or number determines how long the animation will run. (Fool's Pier Note: Default value: "normal", three predetermined speed strings ("slow", "normal", or "fast") or a millisecond value indicating the animation duration (such as: 1000))

2), easing (default: swing)

Type: String

A string indicating which easing function to use for transition. (Note from Fool's Wharf: jQuery itself provides "linear" and "swing", and you can use the jQuery Easing Plugin for other effects)

3), queue (default: true)

Type: Boolean or String

A Boolean value indicating whether to place the animation in the effects queue. If false, the animation will start immediately. Starting with jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used, the animation does not start automatically; you must call .dequeue("queuename") to start it.

4), specialEasing

Type: PlainObject

One or more CSS properties defined by the first parameter properties of this method, and their corresponding easing functions A map of key-value pairs. (New in 1.4)

5),step

Type: Function(Number now, Tween tween)

Every The function that will be called for each animated property of an animated element. This function provides an opportunity to modify the Tween object to change the property values ​​in the settings.

6)、progress

Type: Function( Promise animation, Number progress, Number remainingMs )

Each step animation A function called upon completion, executing a separate function for each animated element, regardless of how many animation properties there are. (version added: 1.8)

7), complete

Type: Function()

Function executed when the animation is completed.

8), done

Type: Function( Promise animation, Boolean jumpedToEnd )

Function executed when the animation is completed. (His Promise object status has been completed). (version added: 1.8)

9), fail

Type: Function( Promise animation, Boolean jumpedToEnd )

animation failed Function to be executed when completed. (His Promise object status is not completed). (version added: 1.8)

10)、always

Type: Function( Promise animation, Boolean jumpedToEnd )

Executed when the animation is completed or stopped when it is not completed function. (His Promise object status is completed or incomplete). (version added: 1.8)

For some basic applications, you can refer to jQuery API, or jQuery API Chinese.

The orange part is what I want to focus on in this article!

PlainObject

PlainObject类型,是Javascript对象包含0个或者跟多键值对。换句话说,PlainObject也是Object对象。但在jQuery文档中,被设计是为了区分其他多种Javascript对象。如null,用户自定义的数组,或者是主机对象向如document,typeof 值都是 “object”。通过jQuery.isPlainObject()方法来判断传入的的参数是否是PlainObject.

var a = [];
var d = document;
var o = {};
 
typeof a; // object
typeof d; // object
typeof o; // object
 
jQuery.isPlainObject( a ); // false
jQuery.isPlainObject( d ); // false
jQuery.isPlainObject( o ); // true

queue

一个布尔值,指示是否将动画放置在效果队列中。如果为false时,将立即开始动画。

它是来决定不同动画进行的顺序。

$( "#block1" ).animate( { width: "90%" }, { queue: false, duration: 3000 })
     .animate({ fontSize: "24px" }, 1500 )
     .animate({ borderRightWidth: "15px" }, 1500 );
 $( "#block2" ).animate({ width: "90%" }, 1000 )
     .animate({ fontSize: "24px" }, 1000 )
     .animate({ borderLeftWidth: "15px" }, 1000 );

#block1要执行的动画中,使用了 queue: false 选项,该动画使元素的宽度扩大到了总宽 90%,并且 文字大小也变大了。一旦字体大小改变完了,边框的动画就会开始。注意到是并且了吗?是同时进行的~~

#block2要执行的动画中,包含了一系列动画,当前一个动画完成时,后一个动画就会开始。

关于 step 就留到下次在讲解吧!

The above is the detailed content of In-depth learning of jQuery Animate (1). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete
Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

JavaScript Frameworks: Powering Modern Web DevelopmentJavaScript Frameworks: Powering Modern Web DevelopmentMay 02, 2025 am 12:04 AM

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

The Relationship Between JavaScript, C  , and BrowsersThe Relationship Between JavaScript, C , and BrowsersMay 01, 2025 am 12:06 AM

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!