UNPKG

vue3-prlx

Version:

This is a package created to practice building Vue TypeScript packages with Vite. ### this is the vue 3 version of (https://github.com/gerasimvol/vue-prlx)

2 lines (1 loc) 2.19 kB
(function(a,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(a=typeof globalThis<"u"?globalThis:a||self,r(a.VuePrlx={}))})(this,function(a){"use strict";function r(i){window.cancelAnimationFrame(i.__prlxRequestAnimationFrameId),delete i.__prlxRequestAnimationFrameId}function l(i,{modifiers:o={},value:e={}}){const t={horizontal:o.horizontal||!1,isParallaxOnMobile:o.mobile||!1,background:o.background||!1,startParallaxFromBottom:e.fromBottom||!1,justAddParallaxValue:e.custom||!1,reverse:e.reverse||!1,speed:e.speed||.15,preserveInitialPosition:e.preserveInitialPosition===!1?e.preserveInitialPosition:!0,direction:e.direction||"y",limit:e.limit||null,mobileMaxWidth:e.mobileMaxWidth||768,isDisabled:e.disabled||!1};t.background&&(t.speed=e.speed||.02,t.limit={min:0,max:100}),t.reverse&&(t.speed=-t.speed),t.isDisabled?r(i):(!(window.innerWidth<t.mobileMaxWidth)||t.isParallaxOnMobile)&&s(i,t)}function s(i,o){const e=o.startParallaxFromBottom?window.innerHeight:window.innerHeight/2;let n=Math.max(window.pageYOffset,document.documentElement.scrollTop,document.body.scrollTop)-x(i)+e;o.preserveInitialPosition&&n<0&&(n=0),p(i)&&f(i,n,o),i.__prlxRequestAnimationFrameId=window.requestAnimationFrame(s.bind(null,i,o))}function f(i,o,e){let t=o*e.speed;e.limit&&(t>e.limit.max&&(t=e.limit.max),t<e.limit.min&&(t=e.limit.min));let n;e.background?n=u:e.justAddParallaxValue?n=c:n=m,n(i,t,e.direction)}function u(i,o,e){i.style.transition="background-position 0.1s ease-out",e==="y"?i.style.backgroundPosition=`50% ${o}%`:i.style.backgroundPosition=`${o}% 50%`}function m(i,o,e){i.style.transition="transform 0.1s ease-out",i.style.transform=`translate${e.toUpperCase()}(${Math.round(o)}px)`}function c(i,o){i.style.setProperty("--parallax-value",o)}const p=(i,{top:o,height:e}=i.getBoundingClientRect())=>o<=innerHeight&&o+e>0,x=i=>{let o=0;do o+=i.offsetTop||0,i=i.offsetParent;while(i);return o},d={created:(i,o)=>{l(i,o)},updated:(i,o)=>{l(i,o)},unmounted:i=>{r(i)}},P={install(i,o){i.directive("prlx",d)}};a.VuePrlx=P,a.vPrlx=d,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});