1/* 2* hoverFlow - A Solution to Animation Queue Buildup in jQuery 3* Version 1.00 4* 5* Copyright (c) 2009 Ralf Stoltze, http://www.2meter3.de/code/hoverFlow/ 6* Dual-licensed under the MIT and GPL licenses. 7* http://www.opensource.org/licenses/mit-license.php 8* http://www.gnu.org/licenses/gpl.html 9*/ 10(function($) { 11 $.fn.hoverFlow = function(type, prop, speed, easing, callback) { 12 // only allow hover events 13 if ($.inArray(type, ['mouseover', 'mouseenter', 'mouseout', 'mouseleave']) == -1) { 14 return this; 15 } 16 17 // build animation options object from arguments 18 // based on internal speed function from jQuery core 19 var opt = typeof speed === 'object' ? speed : { 20 complete: callback || !callback && easing || $.isFunction(speed) && speed, 21 duration: speed, 22 easing: callback && easing || easing && !$.isFunction(easing) && easing 23 }; 24 25 // run immediately 26 opt.queue = false; 27 28 // wrap original callback and add dequeue 29 var origCallback = opt.complete; 30 opt.complete = function() { 31 // execute next function in queue 32 $(this).dequeue(); 33 // execute original callback 34 if ($.isFunction(origCallback)) { 35 origCallback.call(this); 36 } 37 }; 38 39 // keep the chain intact 40 return this.each(function() { 41 var $this = $(this); 42 43 // set flag when mouse is over element 44 if (type == 'mouseover' || type == 'mouseenter') { 45 $this.data('jQuery.hoverFlow', true); 46 } else { 47 $this.removeData('jQuery.hoverFlow'); 48 } 49 50 // enqueue function 51 $this.queue(function() { 52 // check mouse position at runtime 53 var condition = (type == 'mouseover' || type == 'mouseenter') ? 54 // read: true if mouse is over element 55 $this.data('jQuery.hoverFlow') !== undefined : 56 // read: true if mouse is _not_ over element 57 $this.data('jQuery.hoverFlow') === undefined; 58 59 // only execute animation if condition is met, which is: 60 // - only run mouseover animation if mouse _is_ currently over the element 61 // - only run mouseout animation if the mouse is currently _not_ over the element 62 if(condition) { 63 $this.animate(prop, opt); 64 // else, clear queue, since there's nothing more to do 65 } else { 66 $this.queue([]); 67 } 68 }); 69 70 }); 71 }; 72})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.