Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
jquery animation queue
Play lesson

jQuery tutorial for beginners - jquery animation queue

5.0 (2)
25 learners

What you'll learn

This course includes

  • 22.5 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

Link for all dot net and sql server video tutorial playlists https://www.youtube.com/user/kudvenkat/playlists?sort=dd&view=1 Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2015/05/jquery-animation-queue.html 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. https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1 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);

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere