1 line
2.5 KiB
JavaScript
1 line
2.5 KiB
JavaScript
(function(){!function(a){return a.fn.animatext=function(b){var c,d;if(d=a.extend({group:!1,mode:"chars",initDelay:0,speed:200,timeToRelaunch:2e3,reverse:!1,infinite:!1,random:!1,onBegin:function(){},onSuccess:function(){}},b),c=function(b){var c,e,f,g,h,i,j,k,l,m,n,o,p,q;if(d.onBegin(),c=[],g=!1,d.group?a(b).each(function(b,d){return a(d).css("visibility","hidden"),c.push(d)}):(l="",i=b.html().split("<br>"),a(i).each(function(b,c){var e,f;return f="",e=c.split(" "),a(e).each(function(b,c){var e,g;return"chars"===d.mode?(e="",g=c.split(""),a(g).each(function(a,b){return e+='<span class="char'+(a+1)+'" aria-hidden="true" style="visibility:hidden; display:inline-block">'+b+"</span>"}),f+='<span class="word'+(b+1)+'" aria-hidden="true" aria-label="'+c+'" style="display:inline-block">'+e+"</span> "):f+='<span class="word'+(b+1)+'" aria-hidden="true" style="visibility:hidden; display:inline-block">'+c+"</span> "}),l+='<span class="paragraph'+(b+1)+'" aria-hidden="true" aria-label="'+c+'" style="display:inline-block">'+f+"</span><br>"}),b.attr("aria-label",b.text()),b.html(l),f=b.find("span[class^='word']"),"chars"===d.mode?a(f).each(function(b,d){var e;return e=a(d).find("span[class^='char']"),a(e).each(function(a,b){return c.push(b)})}):a(f).each(function(a,b){return c.push(b)})),d.reverse&&!d.random&&c.reverse(),d.random){for(e=[],n=c.length,q=k=o=n;o<=1?k<=1:k>=1;q=o<=1?++k:--k)m=Math.floor(Math.random()*c.length),e.push(c[m]),c.splice(m,1);c=e}return p=function(b){return d.group?a(b).each(function(b,c){return a(c).css("visibility","hidden"),a(c).removeClass("animated"),a(c).removeClass(d.effect)}):(b.find("span").css("visibility","hidden"),b.find("span").removeClass("animated"),b.find("span").removeClass(d.effect)),j()},j=function(){var e,f;return g=!0,f=0,e=setInterval(function(){return f>=c.length&&(clearInterval(e),d.onSuccess(),d.infinite&&setTimeout(function(){return g=!1,p(b)},d.timeToRelaunch)),a(c[f]).css("visibility","visible"),d.effect&&a(c[f]).addClass("animated "+d.effect),f+=1},d.speed)},h=function(b){var c,d,e,f;if(b=a(b),f=a(window),e={top:f.scrollTop(),left:f.scrollLeft()},e.right=e.left+f.width(),e.bottom=e.top+f.height(),c=b.offset(),c.right=c.left+b.width(),c.bottom=c.top+b.height(),d=!(e.right<c.left||e.left>c.right||e.bottom<c.top||e.top>c.bottom),d&&!g)return j()},a(window).on("resize scroll",function(){return h(b)}),a(document).ready(function(){return setTimeout(function(){return h(b)},d.initDelay)})},this.length>0)return d.group?c(this):a(this).each(function(b,d){return c(a(d))})}}(window.jQuery||window.Zepto||window.$)}).call(this); |