// сделано на основе пена http://codepen.io/sitepoint/pen/mweaqm (function($) { var _elements, _options; var methods = { init: function(elements, options) { _elements = elements; _options = options; methods.bind(); }, bind: function() { $(window).scroll(function() { methods.animate(_elements, _options); }); $(window).trigger('scroll'); }, animate: function(elements, options) { var viewheight = $(window).height(), viewtop = $(window).scrolltop(), viewbottom = (viewtop + viewheight); $.each(elements, function() { var elementanimation = $(this).data('animate'), elementoffset = $(this).data('offset'), elementduration = $(this).data('duration'), elementdelay = $(this).data('delay'), elementiteration = $(this).data('iteration'), elementheight = $(this).outerheight(), elementtop = $(this).offset().top, elementbottom = (elementtop + elementheight); if (elementoffset) { elementtop = elementtop + elementoffset; elementbottom = elementbottom - elementoffset; } $(this).css({'-webkit-animation-duration': elementduration, 'animation-duration': elementduration}); $(this).css({'-webkit-animation-delay': elementdelay, 'animation-delay': elementdelay}); $(this).css({'-webkit-animation-iteration-count': elementiteration, 'animation-iteration-count': elementiteration}); if ((elementbottom >= viewtop) && (elementtop <= viewbottom)) { $(this).css('visibility', 'visible'); $(this).addclass('animate__'+elementanimation); $(this).addclass('animate__animated'); } else { if (options.once === false) { $(this).css('visibility', 'hidden'); $(this).removeclass('animate__'+elementanimation); $(this).removeclass('animate__animated'); } } }); } }; jquery.fn.scrolla = function(options) { options = $.extend({ mobile: false, once: false }, options); if (options.mobile === false) { if(/android|webos|iphone|ipod|blackberry|iemobile|opera mini/i.test(navigator.useragent)) { return false; } } methods.init(this, options); }; })(jquery);