1(function($) { 2 3 //custom scroll replacement to allow for interval-based 'polling' 4 //rather than checking on every pixel. 5 var uniqueCntr = 0; 6 $.fn.scrolled = function(waitTime, fn) { 7 if (typeof waitTime === 'function') { 8 fn = waitTime; 9 waitTime = 200; 10 } 11 var tag = 'scrollTimer' + uniqueCntr++; 12 this.scroll(function() { 13 var self = $(this); 14 clearTimeout(self.data(tag)); 15 self.data(tag, setTimeout(function() { 16 self.removeData(tag); 17 fn.call(self[0]); 18 }, waitTime)); 19 }); 20 }; 21 22 $.fn.AniView = function(options) { 23 24 //some default settings. animateThreshold controls the trigger point 25 //for animation and is subtracted from the bottom of the viewport. 26 var settings = $.extend({ 27 animateClass: 'animated', 28 animateThreshold: 0, 29 scrollPollInterval: 20, 30 }, options); 31 32 //keep the matched elements in a variable for easy reference 33 var collection = this; 34 35 //cycle through each matched element and wrap it in a block/div 36 //and then proceed to fade out the inner contents of each matched element 37 // $(collection).each(function(index, element) { 38 // // $(element).wrap('<div class="av-container"></div>'); 39 // $(element).css('opacity', 0); 40 // }); 41 42 /** 43 * returns boolean representing whether element's top is coming into bottom of viewport 44 * 45 * @param HTMLDOMElement element the current element to check 46 */ 47 function EnteringViewport(element) { 48 var elementTop = $(element).offset().top; 49 var viewportBottom = $(window).scrollTop() + $(window).height(); 50 return (elementTop < (viewportBottom - settings.animateThreshold)) ? true : false; 51 } 52 53 /** 54 * cycle through each element in the collection to make sure that any 55 * elements which should be animated into view, are... 56 * 57 * @param collection of elements to check 58 */
59 function RenderElementsCurrentlyInViewport(collection) { 60 $(collection).each(function(index, element) { 61 var elementParentContainer = $(element).parent('.av-container'); 62 if ($(element).is('[data-av-animation]') && !$(elementParentContainer).hasClass('av-visible') && EnteringViewport(elementParentContainer)) { 63 $(element).css('opacity', 1); 64 $(elementParentContainer).addClass('av-visible'); 65 $(element).addClass([settings.animateClass, $(element).attr('data-av-animation')].join(' ')); 66 } 67 }); 68 } 69 70 //on page load, render any elements that are currently/already in view 71 RenderElementsCurrentlyInViewport(collection); 72 73 //enable the scrolled event timer to watch for elements coming into the viewport 74 //from the bottom. default polling time is 20 ms. This can be changed using 75 //'scrollPollInterval' from the user visible options 76 $(window).scrolled(settings.scrollPollInterval, function() { 77 RenderElementsCurrentlyInViewport(collection); 78 }); 79 }; 80})(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.