jquery animation queue
Автор: kudvenkat
Загружено: 2015-05-17
Просмотров: 35998
Описание:
Link for all dot net and sql server video tutorial playlists
https://www.youtube.com/user/kudvenka...
Link for slides, code samples and text version of the video
http://csharp-video-tutorials.blogspo...
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
/ @aarvikitchen5572
In this video we will discuss how jQuery animation queues work.
When several calls to animate() method are chained together. By default these calls are placed into a queue to be executed one after the other in series rather than executing all of them simultaneously in parallel. The name of this queue is fx.
Each HTML element has its own queue. With the following code there will be 5 calls to animate method placed in the queue of each div element. This means both div elements (myDiv1 & myDiv2) may start to execute the first call to animate method more or less at the same time. However, from the given queue the queued methods are executed one after the other in series.
$('#myButton').click(function () {
$('#myDiv1')
.animate({ 'width': 500 }, 1500)
.animate({ 'padding': 20 }, 1500)
.animate({ 'font-size': 50 }, 1500)
.animate({ 'border-width': 10 }, 1500)
.animate({ 'opacity': 1 }, 1500);
$('#myDiv2')
.animate({ 'width': 500 }, 1500)
.animate({ 'padding': 20 }, 1500)
.animate({ 'font-size': 50 }, 1500)
.animate({ 'border-width': 10 }, 1500)
.animate({ 'opacity': 1 }, 1500);
});
The following code finds the total number of method calls waiting in the queue. While the first call to animate method is being executed, the other calls are added to the queue and waiting to be executed one after the other in sequence.
$('#myDiv1')
.animate({ 'width': 500 }, 1500)
.queue(function () {
console.log('Queued calls = ' +
$(this).queue('fx').length); $(this).dequeue();
})
.animate({ 'padding': 20 }, 1500)
.animate({ 'font-size': 50 }, 1500)
.animate({ 'border-width': 10 }, 1500)
.animate({ 'opacity': 1 }, 1500)
.queue(function () {
console.log('Queued calls = ' +
$(this).queue('fx').length); $(this).dequeue();
});
To globally disable all animations
$.fx.off = true or jQuery.fx.off = true
If you want the calls to animate() to be executed simultaneously in parallel, then set queue option to false. Modify the jQuery code as shown below.
$('#myDiv1')
.animate({ 'width': 500 }, { duration: 1500, queue: false })
.animate({ 'padding': 20 }, { duration: 1500, queue: false })
.animate({ 'font-size': 50 }, { duration: 1500, queue: false })
.animate({ 'border-width': 10 }, { duration: 1500, queue: false })
.animate({ 'opacity': 1 }, { duration: 1500, queue: false });
$('#myDiv2')
.animate({ 'width': 500 }, { duration: 1500, queue: false })
.animate({ 'padding': 20 }, { duration: 1500, queue: false })
.animate({ 'font-size': 50 }, { duration: 1500, queue: false })
.animate({ 'border-width': 10 }, { duration: 1500, queue: false })
.animate({ 'opacity': 1 }, { duration: 1500, queue: false });
There are 2 variations of animate method. We discussed Variation 1 in Part 46 of jQuery tutorial. In the code snippet above we are using Variation 2.
Variation 1
.animate( properties [, duration ] [, easing ] [, complete ] )
Variation 2
.animate( properties, options )
For the list of all additional options that you can pass to animate method please check http://api.jquery.com/animate
An easier way to animate multiple css properties simultaneously in parallel, is to include all those css properties in a single JSON object.
$('#myDiv1')
.animate({
'width': 500,
'padding': 20,
'font-size': 50,
'border-width': 10,
'opacity': 1
}, 1500);
$('#myDiv2')
.animate({
'width': 500,
'padding': 20,
'font-size': 50,
'border-width': 10,
'opacity': 1
}, 1500);
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: