-
Notifications
You must be signed in to change notification settings - Fork 2
/
marquee.min.js
1 lines (1 loc) · 4.8 KB
/
marquee.min.js
1
!function(e){e.fn.marquee=function(t){return this.each(function(){function i(){if(a=p.find(".js-marquee-wrapper"),n=p.find(".js-marquee").first(),o){var t=p.height();a.removeAttr("style"),p.height(t),p.find(".js-marquee").css({"float":"none","margin-bottom":d.gap,"margin-right":0}),d.duplicated&&p.find(".js-marquee").last().css({"margin-bottom":0});var i=p.find(".js-marquee").first().height()+d.gap,w=n.data("height");if(w&&d.updateLimit&&Math.abs(i-w)<=d.updateLimit)return;n.data("height",i),d.duration=(parseInt(i,10)+parseInt(t,10))/parseInt(t,10)*d.duration}else{u=p.find(".js-marquee").first().width()+d.gap;var y=n.data("width");if(y&&d.updateLimit&&Math.abs(u-y)<=d.updateLimit)return;n.data("width",u),r=p.width(),d.duration=(parseInt(u,10)+parseInt(r,10))/parseInt(r,10)*d.duration}if(d.duplicated&&(d.duration=d.duration/2),d.allowCss3Support){var x=document.body||document.createElement("div"),q="marqueeAnimation-"+Math.floor(1e7*Math.random()),S="Webkit Moz O ms Khtml".split(" "),j="animation",I="",b="";if(x.style.animation&&(b="@keyframes "+q+" ",l=!0),l===!1)for(var C=0;C<S.length;C++)if(void 0!==x.style[S[C]+"AnimationName"]){var L="-"+S[C].toLowerCase()+"-";j=L+j,m=L+m,b="@"+L+"keyframes "+q+" ",l=!0;break}l&&(I=q+" "+d.duration/1e3+"s "+d.delayBeforeStart/1e3+"s infinite "+d.css3easing,p.data("css3AnimationIsSupported",!0))}var A=function(){a.css("margin-top","up"==d.direction?t+"px":"-"+i+"px")},k=function(){a.css("margin-left","left"==d.direction?r+"px":"-"+u+"px")};d.duplicated?(o?a.css("margin-top","up"==d.direction?t+"px":"-"+(2*i-d.gap)+"px"):a.css("margin-left","left"==d.direction?r+"px":"-"+(2*u-d.gap)+"px"),f=1):o?A():k();var M=function(){if(d.duplicated&&(1===f?(d._originalDuration=d.duration,d.duration=o?"up"==d.direction?d.duration+t/(i/d.duration):2*d.duration:"left"==d.direction?d.duration+r/(u/d.duration):2*d.duration,I&&(I=q+" "+d.duration/1e3+"s "+d.delayBeforeStart/1e3+"s "+d.css3easing),f++):2===f&&(d.duration=d._originalDuration,I&&(q+="0",b=e.trim(b)+"0 ",I=q+" "+d.duration/1e3+"s 0s infinite "+d.css3easing),f++)),o?d.duplicated?(f>2&&a.css("margin-top","up"==d.direction?0:"-"+i+"px"),s={"margin-top":"up"==d.direction?"-"+i+"px":0}):(A(),s={"margin-top":"up"==d.direction?"-"+a.height()+"px":t+"px"}):d.duplicated?(f>2&&a.css("margin-left","left"==d.direction?0:"-"+u+"px"),s={"margin-left":"left"==d.direction?"-"+u+"px":0}):(k(),s={"margin-left":"left"==d.direction?"-"+u+"px":r+"px"}),p.trigger("beforeStarting"),l){a.css(j,I);var n=b+" { 100% "+g(s)+"}",m=e("head");m.find("style#marquee").remove(),m.append('<style type="text/css" id="marquee">'+n+"</style>"),c(a[0],"AnimationIteration",function(){p.trigger("finished")}),c(a[0],"AnimationEnd",function(){M(),p.trigger("finished")})}else a.animate(s,d.duration,d.easing,function(){p.trigger("finished"),d.pauseOnCycle?h(M):M()});p.data("runningStatus","resumed")};p.off("pause").on("pause",v.pause),p.off("resume").on("resume",v.resume),d.pauseOnHover&&p.on("mouseenter mouseleave",v.toggle),l&&d.allowCss3Support?M():h(M)}var a,n,r,s,o,u,d=e.extend({},e.fn.marquee.defaults,t),p=e(this),f=3,m="animation-play-state",l=!1,c=function(e,t,i){for(var a=["webkit","moz","MS","o",""],n=0;n<a.length;n++)a[n]||(t=t.toLowerCase()),e.addEventListener(a[n]+t,i,!1)},g=function(e){var t=[];for(var i in e)e.hasOwnProperty(i)&&t.push(i+":"+e[i]);return t.push(),"{"+t.join(",")+"}"},h=function(e){p.timer=setTimeout(e,d.delayBeforeStart)},v={pause:function(){l&&d.allowCss3Support?a.css(m,"paused"):e.fn.pause&&a.pause(),p.data("runningStatus","paused"),p.trigger("paused")},resume:function(){l&&d.allowCss3Support?a.css(m,"running"):e.fn.resume&&a.resume(),p.data("runningStatus","resumed"),p.trigger("resumed")},toggle:function(){v["resumed"==p.data("runningStatus")?"pause":"resume"]()},html:function(e){n=p.find(".js-marquee");var t=n.first().html();"string"==typeof e&&t!=e&&(n.html(e),i())},destroy:function(){clearTimeout(p.timer),p.find("*").off(),p.off(),p.html(p.find(".js-marquee").first().html())}};if("string"==typeof t||d.html)return void(e.isFunction(v[t])?(a||(a=p.find(".js-marquee-wrapper")),p.data("css3AnimationIsSupported")===!0&&(l=!0),v[t]()):v.html(d.html||t));var w;e.each(d,function(e){if(w=p.attr("data-"+e),null!=w&&"undefined"!=typeof w){switch(w){case"true":w=!0;break;case"false":w=!1}d[e]=w}}),d.duration=d.speed||d.duration,o="up"==d.direction||"down"==d.direction,d.gap=d.duplicated?parseInt(d.gap):0,p.wrapInner('<div class="js-marquee"></div>');var y=p.find(".js-marquee").css({"margin-right":d.gap,"float":"left"});d.duplicated&&y.clone(!0).appendTo(p),p.wrapInner('<div style="width:100000px" class="js-marquee-wrapper"></div>'),i()})},e.fn.marquee.defaults={allowCss3Support:!0,css3easing:"linear",easing:"linear",delayBeforeStart:1e3,direction:"left",duplicated:!1,duration:8e3,gap:20,pauseOnCycle:!1,pauseOnHover:!1,updateLimit:50}}(window.jQuery||window.Zepto);