jquery-css3-animation-queue
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -10,3 +10,3 @@ /*! | ||
* Version | ||
* 1.0.3 | ||
* 1.0.4 | ||
* | ||
@@ -23,9 +23,10 @@ * Copyright (c) 2016 Richard Hung. | ||
// Transitions | ||
// Global Variables | ||
var queue = []; // Queue of elements that have reached animation break point | ||
var transitionObjects = $('.animated.standby'); // All elements to be animated | ||
var queueActive = false; // Check if queue is in process, to not run multiple queues concurrently | ||
var methods = {}; // Plugin methods | ||
// Sort array by element top including offset | ||
var arraySort = function(a,b) { | ||
methods.sortByOffsetTop = function(a,b) { | ||
var a_offset = 50; | ||
@@ -52,3 +53,3 @@ var b_offset = 50; | ||
// Recusive loop to process queue | ||
var processQueue = function() { | ||
methods.processQueue = function() { | ||
// If queue is not in process and has elements, run one element through animation queue | ||
@@ -75,3 +76,3 @@ if (!queueActive && queue.length) { | ||
queueActive = false; | ||
processQueue(); | ||
methods.processQueue(); | ||
},delay); | ||
@@ -81,5 +82,6 @@ | ||
}; | ||
var addToQueue = function() { | ||
methods.addToQueue = function() { | ||
var scroll_top = $(window).scrollTop(); | ||
var window_height = $(window).height(); | ||
var apply_sort = false; | ||
@@ -101,12 +103,16 @@ // Loop through list of elements waiting for animation | ||
queue.push(element); | ||
queue.sort(arraySort); | ||
// Remove this element from list of waiting animation elements | ||
transitionObjects = transitionObjects.not(this); | ||
apply_sort = true; | ||
} | ||
}); | ||
if (apply_sort) { | ||
queue.sort(methods.sortByOffsetTop); | ||
} | ||
}; | ||
// Animate all elements above fold immediately without adding to queue | ||
var immediateAnimation = function(scroll_top) { | ||
methods.immediateAnimation = function(scroll_top) { | ||
// Check if a position top is passed | ||
@@ -133,3 +139,24 @@ if (!scroll_top) { | ||
$(window).on('load',function() { | ||
// Update queue with new animatable elements | ||
methods.update = function() { | ||
transitionObjects = $('.animated.standby'); | ||
queue = []; | ||
methods.addToQueue(); | ||
methods.processQueue(); | ||
} | ||
$.fn.jqueryCss3AnimationQueue = function(method) { | ||
if ( methods[method] ) { | ||
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); | ||
} else if ( typeof method === 'object' || ! method ) { | ||
return methods.init.apply( this, arguments ); | ||
} else { | ||
$.error( 'Method ' + method + ' does not exist on jQuery.jqueryCss3AnimationQueue' ); | ||
} | ||
}; // End plugin | ||
$(document).ready(function() { | ||
// Cache all animated elements | ||
@@ -139,13 +166,13 @@ transitionObjects = $('.animated.standby'); | ||
// Run once for elements above fold | ||
immediateAnimation(); | ||
methods.immediateAnimation(); | ||
addToQueue(); | ||
processQueue(); | ||
methods.addToQueue(); | ||
methods.processQueue(); | ||
}); // end document ready | ||
}); // End window ready | ||
$(window).scroll(function() { | ||
addToQueue(); | ||
processQueue(); | ||
methods.addToQueue(); | ||
methods.processQueue(); | ||
}); | ||
})(jQuery); |
{ | ||
"name": "jquery-css3-animation-queue", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Queue CSS3 animations to display when browser scrolls down to see element in viewport", | ||
@@ -5,0 +5,0 @@ "main": "jquery-css3-animation-queue.js", |
@@ -53,2 +53,4 @@ # jQuery CSS3 Animation Queue | ||
### Options | ||
The plugin reads the data properties `delay` and `offset` on each element. | ||
@@ -65,3 +67,15 @@ | ||
``` | ||
### Methods | ||
The plugin comes with several methods that you can call manually from outside the plugin. The most common one is `update`. | ||
The plugin caches all animated elements on document ready in order to improve performance. The `update` method will clear the animation queue and reacquire elements with the classes `animated` and `standby`. | ||
``` | ||
$('.newly_added_div').addClass('animated standby fadeIn'); | ||
$.fn.jqueryCss3AnimationQueue('update'); | ||
``` | ||
## License | ||
jQuery CSS3 Animation Queue is licensed under the MIT license. (http://opensource.org/licenses/MIT) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12755
154
80