UNPKG

zz-shopify-components

Version:

Reusable Shopify components for theme projects

3 lines (2 loc) 932 B
var isMdPc=!0;window.innerWidth<=1e3&&(isMdPc=!1);class LazyVideo extends HTMLElement{$video;observer;isMdPc=isMdPc;cH=document.documentElement.clientHeight;RATIO=.7;constructor(){super(),this.$video=this.querySelector(".as-video"),this.$video!==null&&this.setIntersectionObserve()}setIntersectionObserve(){this.observer=new IntersectionObserver(this.callback.bind(this),{root:null,rootMargin:`${this.cH*this.RATIO}px 0px ${this.cH*this.RATIO}px 0px`}),this.observer.observe(this.$video)}callback(entries){entries.forEach(entry=>{entry.isIntersecting&&(this.lazyLoadingVideo(),this.observer.disconnect())})}lazyLoadingVideo(){this.$video!==null&&(this.isMdPc?this.$video.src=this.$video.dataset?.pcVideo:this.$video.src=this.$video.dataset?.mobVideo)}}customElements.get("lazy-video")===void 0&&customElements.define("lazy-video",LazyVideo); //# sourceMappingURL=/s/files/1/0796/1362/4605/t/81/assets/lazy-video.js.map?v=1721458946