1(function($) { 2 3 /** 4 * Copyright 2012, Digital Fusion 5 * Licensed under the MIT license. 6 * http://teamdf.com/jquery-plugins/license/ 7 * 8 * @author Sam Sehnert 9 * @desc A small plugin that checks whether elements are within 10 * the user visible viewport of a web browser. 11 * only accounts for vertical position, not horizontal. 12 */ 13 14 $.fn.visible = function(partial) { 15 16 var $t = $(this), 17 $w = $(window), 18 viewTop = $w.scrollTop(), 19 viewBottom = viewTop + $w.height(), 20 _top = $t.offset().top, 21 _bottom = _top + $t.height(), 22 compareTop = partial === true ? _bottom : _top, 23 compareBottom = partial === true ? _top : _bottom; 24 25 if($t.hasClass('visible')){ 26 return false; 27 } 28 29 return ((compareBottom <= viewBottom) && (compareTop >= viewTop)); 30 31 }; 32 33 var addAnimation = function(element){ 34 $(element).each(function(i, el){ 35 var el = $(el); 36 if (el.visible(true)) { 37 el.removeClass('visible').addClass('animated'); 38 } 39 }); 40 } 41 42 var checkVisible = function(element){ 43 $(element).each(function(i, el) { 44 var el = $(el); 45 if (el.visible(false)) { 46 el.addClass("visible"); 47 } 48 }); 49 } 50 51 $(window).load(function(){ 52 checkVisible('.animation'); 53 }); 54 55 $(window).scroll(function(event) { 56 addAnimation('.animation'); 57 }); 58 59})(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.