forked from ezekielaquino/Marquee3000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
marquee3k.min.js
1 lines (1 loc) · 3.72 KB
/
marquee3k.min.js
1
'use strict';var _createClass=function(){function a(b,c){for(var e,d=0;d<c.length;d++)e=c[d],e.enumerable=e.enumerable||!1,e.configurable=!0,'value'in e&&(e.writable=!0),Object.defineProperty(b,e.key,e)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),_typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&'function'==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?'symbol':typeof a};function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}(function(a,b){'function'==typeof define&&define.amd?define([],b):'object'===('undefined'==typeof exports?'undefined':_typeof(exports))?module.exports=b():a.Marquee3k=b()})(void 0,function(){'use strict';var a=function(){function b(c,d){_classCallCheck(this,b),this.element=c,this.selector=d.selector,this.speed=c.dataset.speed||0.25,this.pausable=c.dataset.pausable,this.reverse=c.dataset.reverse,this.paused=!1,this.parent=c.parentElement,this.parentProps=this.parent.getBoundingClientRect(),this.content=c.children[0],this.innerContent=this.content.innerHTML,this.wrapStyles='',this.offset=0,this._setupWrapper(),this._setupContent(),this._setupEvents(),this.wrapper.appendChild(this.content),this.element.appendChild(this.wrapper)}return _createClass(b,[{key:'_setupWrapper',value:function _setupWrapper(){this.wrapper=document.createElement('div'),this.wrapper.classList.add('marquee3k__wrapper'),this.wrapper.style.whiteSpace='nowrap'}},{key:'_setupContent',value:function _setupContent(){this.content.classList.add(this.selector+'__copy'),this.content.style.display='inline-block',this.contentWidth=this.content.offsetWidth,this.requiredReps=this.contentWidth>this.parentProps.width?2:Math.ceil((this.parentProps.width-this.contentWidth)/this.contentWidth)+1;for(var c=0;c<this.requiredReps;c++)this._createClone();this.reverse&&(this.offset=-1*this.contentWidth),this.element.classList.add('is-init')}},{key:'_setupEvents',value:function _setupEvents(){var c=this;this.element.addEventListener('mouseenter',function(){c.pausable&&(c.paused=!0)}),this.element.addEventListener('mouseleave',function(){c.pausable&&(c.paused=!1)})}},{key:'_createClone',value:function _createClone(){var c=this.content.cloneNode(!0);c.style.display='inline-block',c.classList.add(this.selector+'__copy'),this.wrapper.appendChild(c)}},{key:'animate',value:function animate(){if(!this.paused){var c=this.reverse?0>this.offset:this.offset>-1*this.contentWidth,d=this.reverse?-1:1,e=this.reverse?-1*this.contentWidth:0;c?this.offset-=this.speed*d:this.offset=e,this.wrapper.style.whiteSpace='nowrap',this.wrapper.style.transform='translate('+this.offset+'px, 0) translateZ(0)'}}},{key:'_refresh',value:function _refresh(){this.contentWidth=this.content.offsetWidth}},{key:'repopulate',value:function repopulate(c,d){if(this.contentWidth=this.content.offsetWidth,d)for(var e=Math.ceil(c/this.contentWidth)+1,f=0;f<e;f++)this._createClone()}}],[{key:'refresh',value:function refresh(c){MARQUEES[c]._refresh()}},{key:'refreshAll',value:function refreshAll(){for(var c=0;c<MARQUEES.length;c++)MARQUEES[c]._refresh()}},{key:'init',value:function init(){var l=this,d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{selector:'marquee3k'};function c(){for(var m=0;m<MARQUEES.length;m++)MARQUEES[m].animate();window.requestAnimationFrame(c)}window.MARQUEES=[];for(var e=Array.from(document.querySelectorAll('.'+d.selector)),f=window.innerWidth,h=0;h<e.length;h++){var j=e[h],k=new b(j,d);MARQUEES.push(k)}c(),window.addEventListener('resize',function(){clearTimeout(g),g=setTimeout(function(){for(var m=f<window.innerWidth,n=window.innerWidth-f,o=0;o<MARQUEES.length;o++)MARQUEES[o].repopulate(n,m);f=l.innerWidth})},250)}}]),b}();return a});