futura.js
Version:
A small JavaScript library for common tasks such as Carousel, Exception, Animation handler and more...
9 lines (8 loc) • 3.1 kB
JavaScript
const DEFAULT_INTERSECTION_OPTION$$module$lib$Utils={root:null,ratio:.2,rootMargin:"0px",threshold:.7,timeout:200},DATA_INTERSECTION_VISIBLE$$module$lib$Utils="data-fv-visible";
class Utils$$module$lib$Utils{IntersectionHandler(a={elt:"",visible:null,invisible:null,options:{}}){const b=a.options??DEFAULT_INTERSECTION_OPTION$$module$lib$Utils;if(IntersectionObserver){const c=new IntersectionObserver(function(d,f){d.forEach(function(g){let e=g.target;g.intersectionRatio>b.ratio?e.hasAttribute(DATA_INTERSECTION_VISIBLE$$module$lib$Utils)||(a.visible?a.visible(e):!1,e.setAttribute(DATA_INTERSECTION_VISIBLE$$module$lib$Utils,!0)):a.invisible?a.invisible(e):!1})},b);a.elt.forEach(function(d,
f){c.observe(d)})}}}var module$lib$Utils={};module$lib$Utils.default=Utils$$module$lib$Utils;const DATA_VALUE$$module$lib$core$Animation="data-fv-data",COUNTDOWN_SELECTOR$$module$lib$core$Animation="[data-fv-anim='countdown']",AUTOWRITE_SELECTOR$$module$lib$core$Animation="[data-fv-anim='autowrite']";let utils$$module$lib$core$Animation=new Utils$$module$lib$Utils;
class Intersection$$module$lib$core$Animation{constructor(a={elt:"",class:""}){a.elt=document.querySelectorAll(a.elt);a.class=a.class.trim();this.options=a;this.run()}run(){let a=this.options,b=a.class.split(" ");utils$$module$lib$core$Animation.IntersectionHandler({elt:this.options.elt,options:a,visible:function(c){b.forEach(d=>c.classList.add(d))}})}}
class NumberAutoCount$$module$lib$core$Animation{constructor(a=200){this.timeout=a;this.nodeListOfElements=document.querySelectorAll(COUNTDOWN_SELECTOR$$module$lib$core$Animation);this.begin()}begin(){utils$$module$lib$core$Animation.IntersectionHandler({elt:this.nodeListOfElements,visible:a=>this.count(a)})}count(a){const b=a.getAttribute(DATA_VALUE$$module$lib$core$Animation);let c=0,d=setInterval(()=>{c<=b?a.innerText=c:this.stopCount(d);c++},this.timeout)}stopCount(a){clearInterval(a)}}
class AutoWriteText$$module$lib$core$Animation{constructor(a={timeout:300,separator:"|"}){this.timeout=a.timeout??300;this.separator=a.separator??"";this.nodeListOfElements=document.querySelectorAll(AUTOWRITE_SELECTOR$$module$lib$core$Animation);this.begin()}begin(){utils$$module$lib$core$Animation.IntersectionHandler({elt:this.nodeListOfElements,visible:a=>this.write(a)})}write(a){let b=0,c=a.getAttribute(DATA_VALUE$$module$lib$core$Animation),d=setInterval(()=>{let f=a.innerHTML.split(` ${this.separator}`);
b<c.length?a.innerHTML=`${f[0]}${c[b]} ${this.separator}`:this.stopWrite(a,d);b++},this.timeout)}stopWrite(a,b){clearInterval(b);a.innerHTML=a.innerHTML.split(` ${this.separator}`)[0]}}window.fJs.Intersection=Intersection$$module$lib$core$Animation;window.fJs.NumberAutoCount=NumberAutoCount$$module$lib$core$Animation;window.fJs.AutoWriteText=AutoWriteText$$module$lib$core$Animation;var module$lib$core$Animation={};module$lib$core$Animation.AutoWriteText=AutoWriteText$$module$lib$core$Animation;
module$lib$core$Animation.Intersection=Intersection$$module$lib$core$Animation;module$lib$core$Animation.NumberAutoCount=NumberAutoCount$$module$lib$core$Animation;