1 line
1 KiB
JavaScript
1 line
1 KiB
JavaScript
$(function(){var u={strings:["Hello!","How are you?"],waitFillDuration:200,waitEraseDuration:2e3,animateDuration:400,easing:"swing"};function t(i,t){var n,e=i,a=!1,o=2,s=0,r=$.extend({},u,t),l=this;this.animateFill=function(){var i=r.strings[s];e.html(i),e.parent().find(n).remove(),(n=e.clone()).css({width:"",position:"absolute",visibility:"hidden",display:"block",left:"-300%"}),e.parent().append(n),e.velocity({width:n.width()},{duration:r.animateDuration,easing:r.easing,complete:l.next})},this.animateErase=function(){e.velocity({width:0},{duration:r.animateDuration,easing:r.easing,complete:l.next})},this.next=function(){switch(s=(s+1)%r.strings.length,o){case 2:o=1,setTimeout(l.animateFill.bind(l),r.waitFillDuration);break;case 1:a||(o=2,setTimeout(l.animateErase.bind(l),r.waitEraseDuration))}},this.start=function(){a=!1,l.next()},this.stop=function(){a=!0},e.css({boxSizing:"border-box",display:"inline-block",overflow:"hidden",whiteSpace:"nowrap",verticalAlign:"bottom",width:0}),l.start()}$.fn.fluidType=function(i){return new t($(this),i)}});
|