;(function ($, window, document, undefined) { 'use strict'; if($('.parallax-showcase-wrapper .title:not(.animation-title)').length){ $(document).on('ready', function () { $('.parallax-showcase-wrapper .parallax-showcase-item').each(function () { var textLength = $(this).find('.title').text().length, time = (textLength+1)*100; $(this).find('.title').attr('time', time); }); }); $(window).on('load scroll', function () { $('.parallax-showcase-wrapper .parallax-showcase-item').each(function () { if ($(window).scrollTop() >= $(this).find('.title').offset().top - $(window).height() * .9) { var end = $(this).find('.title').attr('time'); $(this).find('.title:not(.done)').addClass('animation-title'); var elements = $(this).find('.animation-title'); Array.prototype.forEach.call(elements, function (el) { var chaffle = new Chaffle(el, { }); chaffle.init(); }); $(this).find('.title:not(.done)').delay(end).addClass('done').removeClass('animation-title'); } }); }); } })(jQuery, window, document);