Summary of animation processing under jQuery_jquery
queue()/dequeue()
These two methods are as hidden as Ajax’s XMLHttpRequest object and are not known to ordinary people. These two methods are very useful when processing animations. We often write some code like this
$('#test').animate({
"width": "300px",
"height": "300px",
"opacity":"1"
});
In this way, the height, width, and opacity of the test div change at the same time. Sometimes we don’t want to execute it synchronously, but separate the change of shape and the change of transparency. First it becomes a 300*300 div, and then the transparency gradually changes. , we need to write like this
$('#test').animate({
"width": "300px",
"height": "300px",
}, function () {
"$('#test').animate({ "opacity": "1 " });
});
Students can imagine what the code would look like if there were ten animation processes. queue() and dequeue() can solve such problems. Create a queue for all process methods and let the functions be called in sequence. First Take a look at the syntax
queue( [queueName ], newQueue ) The operation wants to execute the queue method
The first parameter is the queue name. If not written, the default is fx
The second parameter can be a function array to store all queue functions, or it can be a callback function to add new functions to the queue
dequeue( [queueName ] ) Execute the next function in the queue for the matching element
Every time this method is called, the next function in the queue is executed
var q = [
🎜> $(this).animate({
“ 🎜>
function next(){
$('#test').dequeue('myQueue');
}
$('#test').queue('myQueue', q);
The above code can make the test div first change to 200*200, and then change to 400*400. Each animation executes the callback function, calls the next method in the queue, and the two animations are executed in sequence. If If you want to add a function during execution, you can do this
Copy code
The code is as follows:
var q = [
function () {
$(this).animate({
"width": "200px",
"height":"200px"
}, next)
},
function () {
$(this).animate({
"width": "400px",
"height": "400px"
}, next);
}
];
function next(){
$('#test').dequeue('myQueue');
}
$('#test').queue('myQueue', q);
next();
$('#test').queue('myQueue',function () {
$(this).slideUp().dequeue('myQueue');
});
总而言之这两个方法就是为了方便动画按照预定次序执行
clearQueue() /stop()
这两个方法主要是为了取消动画
clearQueue( [queueName ] ) 将队列中函数清空
stop( [queue ] [, clearQueue ] [, jumpToEnd ] ) 用于停止正在进行的动画
queue:正在进行的动画队列名称
clearQueue:默认值为false,是否将队列本身也清空
jumpToEnd:默认值为false,是否立即执行完动画
如果想停止刚才动画可以这么写
这样写不会不会终止动画,只是当前动画执行完后,不会再调用队列中下一个动画(队列被清空了嘛,没有下一个了),如果想立即停止动画,可以这么写
As for whether the stop animation is paused or executed immediately, you need to configure the parameters of stop()
slideDown()/ slideUp()/ slideToggle()
The slide effect is often used when making animations, especially menus. These three functions are very simple, that is, the element shrinks/stretches/automatically determines the shrinking and stretching, but its parameters are not only duration, we can also add For some other controls, take a look at the introduction in the API. The Sanger function parameters are similar. Here is an example of slideUp
slideUp( [duration ] [, easing ] [, complete ] ) easing is a gradient method. I have never changed this manually. If duration is not written, it will take about one second to complete the animation by default
slideUp(options)
Commonly used configurations in options include
duration: animation time
queue: You will understand this after reading the above
step: Executed every time the attribute changes during the animation
complete: Executed when the animation is completed
start: Executed when the animation starts
always: Occurs when the animation is terminated or unexpectedly fails to complete
These three functions will modify the height of the element when executed. After sideUp() is executed, the height will be restored and the dialog will be set to none
fadeIn()/ fadeOut()/ fadeToggle()/ fadeTo()
The usage of fadeIn()/ fadeOut()/ fadeToggle() is similar to the slide series, no longer Explain one by one, only these three functions modify the transparency of the element. After the fadeOut() function is executed, it will restore the opacity of the element and set the display attribute to none
fadeTo( duration, opacity [, easing ] [, complete ] ) The fadeTo() method is not that complicated, but the duration and opacity of fadeTO() are not omissible and must be written
show()/ hide()/ toggle()
The usage of these three functions is the same as the slide series, but there are a few differences in effects
1. If the parameter duration is not written, it will be executed immediately without animation
2. This animation modifies the height, width, and opacity attributes at the same time
3. After the execution of hide() is completed, the height, width, and opacity attributes will be restored, and the display will be set to none
animate()
Some complex animations cannot be realized by relying on the above functions. This is when the powerful animate comes in handy. There are two ways to use animate()
.animate( properties [, duration ] [, easing ] [, complete ] )
Most attributes do not need explanation. Properties are json. The value of the attribute can be a literal, function, "toggle", or simple expression. If it is a function, the return value will be assigned to the attribute. Students who are familiar with jQuery will definitely understand." What is "toggle" is to switch an attribute between the initial value and the minimum value. The attributes that can use toggle include width, height, opacity, etc., including numeric value attributes. The simple expressions are =, -=, etc., for example, it can be like this "width":" =10px".
$( "#block" ).animate({
width: "70%",
opacity: 0.4,
marginLeft: "0.6in",
fontSize: "3em",
borderWidth: " =10px"
}, 1500 );
If a callback function is passed in, the function will be called after the animation is executed
.animate( properties, options )
This usage is more flexible, the properties are the same as the previous usage, and the commonly used options are
duration: animation time
queue: function queue
step: the rollback function for each attribute adjustment
complete: the callback function to complete the animation
start: Called when the animation starts
always: Occurs when the animation is terminated or unexpectedly fails to complete
If jQuery is easy to use, are the above configurations very familiar?
$( "#book" ).animate({
width: "toggle",
height: "toggle"
}, {
duration: 5000,
specialEasing: {
width: "linear",
height: " easeOutBounce"
},
complete: function() {
$( this ).after( "
}
} );
hover()
Strictly speaking, this is not an animation function, but because the hover of lower versions of IE does not work for many elements, many actions cannot be completed with CSS, so it is often used. JavaScript handles the haver event.
.hover( handlerIn(eventObject), handlerOut(eventObject) )
The method is very simple, I won’t introduce it in detail, so you can write mousein and mouseout together.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

JavaScript can be run in PowerPoint, and can be implemented by calling external JavaScript files or embedding HTML files through VBA. 1. To use VBA to call JavaScript files, you need to enable macros and have VBA programming knowledge. 2. Embed HTML files containing JavaScript, which are simple and easy to use but are subject to security restrictions. Advantages include extended functions and flexibility, while disadvantages involve security, compatibility and complexity. In practice, attention should be paid to security, compatibility, performance and user experience.

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.
