ukiyojs
Advanced tools
Comparing version 4.0.0 to 4.0.1
module.exports = { | ||
root: true, | ||
extends: [ | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'prettier' | ||
'prettier', | ||
], | ||
plugins: [ | ||
'@typescript-eslint', | ||
], | ||
plugins: ['@typescript-eslint'], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: './tsconfig.json' | ||
project: './tsconfig.json', | ||
}, | ||
} | ||
}; |
module.exports = { | ||
semi: true, | ||
useTabs: false, | ||
printWidth: 160, | ||
singleQuote: true, | ||
arrowParens: 'always', | ||
} | ||
trailingComma: 'all', | ||
}; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Ukiyo=e()}(this,(function(){"use strict";var t=function(t){return Array.prototype.slice.call(t)},e=function(){var t=window.navigator.userAgent,e=!!t.match(/iPad/i)||!!t.match(/iPhone/i),i=!!t.match(/WebKit/i);return e&&i&&!t.match(/CriOS/i)},i={scale:1.5,speed:1.5,wrapperClass:null,willChange:!1,externalRAF:!1},n=function(t,e){var n=this;if(this.element=t,this.wrapper=document.createElement("div"),this.options=Object.assign({},i,e),this.updateOptions(),this.vh=document.documentElement.clientHeight,this.isVisible=!1,this.damp=this.calcDamp(document.documentElement.clientWidth),this.elementTagName=this.element.tagName.toLowerCase(),"img"===this.elementTagName){var o=this.element.getAttribute("src");if(!o)return;(async function(t){var e=new Image;return e.src=t,await e.decode(),e})(o).then((function(){n.createParallax()}))}else this.createParallax()};n.prototype.createParallax=function(){this.setStyle(!0),this.wrapElement(),e()||this.createObserver()},n.prototype.updateOptions=function(){var t=this.element.getAttribute("data-u-scale"),e=this.element.getAttribute("data-u-speed"),i=this.element.getAttribute("data-u-willchange");null!==t&&(this.options.scale=Number(t)),null!==e&&(this.options.speed=Number(e)),null!==i&&(this.options.willChange=!0)},n.prototype.setStyle=function(t){void 0===t&&(t=!1);var e=this.element.clientHeight,i=this.element.clientWidth,n=window.getComputedStyle(this.element),o="absolute"===n.position,s=this.wrapper.style,r=this.element.style;this.overflow=Math.floor(10*(e-e*this.options.scale))/10,this.overflowAbs=Math.abs(this.overflow),o&&"0px"!==n.marginRight&&"0px"!==n.marginLeft&&n.marginLeft===n.marginRight&&(s.margin="auto"),"0px"===n.marginTop&&"0px"===n.marginBottom||(s.marginTop=n.marginTop,s.marginBottom=n.marginBottom,r.marginTop="0",r.marginBottom="0"),"auto"!==n.inset&&(s.top=n.top,s.right=n.right,s.bottom=n.bottom,s.left=n.left,r.top="0",r.right="0",r.bottom="0",r.left="0"),"none"!==n.transform&&(s.transform=n.transform),"auto"!==n.zIndex&&(s.zIndex=n.zIndex),s.position=o?"absolute":"relative","auto"!==n.gridArea&&"auto / auto / auto / auto"!==n.gridArea&&(s.gridArea=n.gridArea,r.gridArea="auto"),t&&(s.width="100%",s.overflow="hidden",r.display="block",r.overflow="hidden",r.backfaceVisibility="hidden","0px"!==n.padding&&(r.padding="0"),"img"===this.elementTagName?r.objectFit="cover":"video"!==this.elementTagName&&(r.backgroundPosition="center")),"0px"!==n.borderRadius&&(s.borderRadius=n.borderRadius,s.isolation||(s.isolation="isolate"),"0px"!==n.marginLeft&&(s.marginLeft=n.marginLeft,r.marginLeft="0"),"0px"!==n.marginRight&&(s.marginRight=n.marginRight,r.marginRight="0"),s.width=i+"px",r.width=i+"px"),o&&(s.width=i+"px",r.width="100%"),"none"!==n.maxHeight&&(s.maxHeight=n.maxHeight,r.maxHeight="none"),"0px"!==n.minHeight&&(s.minHeight=n.minHeight,r.minHeight="none"),s.height=e+"px",r.height=e*this.options.scale+"px",this.wrapperHeight=e},n.prototype.wrapElement=function(){var t=this.element.getAttribute("data-u-wrapper-class")||this.options.wrapperClass;t&&this.wrapper.classList.add(t);var e=this.element.closest("picture");if(null!==e)null!==e.parentNode&&e.parentNode.insertBefore(this.wrapper,e),this.wrapper.appendChild(e);else{var i=this.element.parentNode;null!==i&&i.insertBefore(this.wrapper,this.element),this.wrapper.appendChild(this.element)}},n.prototype.checkVisible=function(){var t=this.wrapper.getBoundingClientRect();0<t.bottom&&t.top<this.vh?this.onEnter():this.onLeave()},n.prototype.createObserver=function(){this.observer=new IntersectionObserver(this.handleIntersect.bind(this),{root:null,rootMargin:"0px",threshold:0}),this.observer.observe(this.wrapper)},n.prototype.handleIntersect=function(t){t[0].isIntersecting?this.onEnter():this.onLeave()},n.prototype.onEnter=function(){var t=this.element.style;this.options.willChange&&"transform"!==t.willChange&&(t.willChange="transform"),this.isVisible=!0},n.prototype.onLeave=function(){var t=this.element.style;this.options.willChange&&"transform"===t.willChange&&(t.willChange=""),this.isVisible=!1},n.prototype.calcTranslateValue=function(){var t=window.pageYOffset;t<0&&(t=0);var e=this.wrapper.getBoundingClientRect().top+t,i=(t+this.vh-e)/((this.vh+this.wrapperHeight)/100),n=Math.min(100,Math.max(0,i))/100,o=this.overflow+this.overflowAbs*n*this.options.speed*this.damp;return Number(o.toFixed(4))},n.prototype.calcDamp=function(t){var e=this.options.scale,i=this.options.speed;if((i>=1.4||e>=1.4)&&t<=1e3){e<1&&(e=1),i<1&&(i=1);var n=1.2-(1-(t/1e3+(3-(e+i)))),o=Math.max(.5,Math.min(1,n));return Math.floor(100*o)/100}return 1},n.prototype.transformParallax=function(){this.element.style.transform="translate3d(0 , "+this.calcTranslateValue()+"px , 0)"},n.prototype.animate=function(){e()&&this.checkVisible(),window.pageYOffset<0||this.isVisible&&this.transformParallax()},n.prototype.reset=function(){this.damp=this.calcDamp(window.innerWidth);var t=this.wrapper.style,e=this.element.style;this.vh=document.documentElement.clientHeight,t.width="",t.position="",t.height="100%",e.width="","img"===this.elementTagName&&"absolute"===t.position&&(t.height="100%"),""===t.gridArea?e.height="":e.height="100%","0px"!==t.margin&&(t.margin="",e.margin=""),"auto"!==t.inset&&(t.top="",t.right="",t.bottom="",t.left="",e.top="",e.right="",e.bottom="",e.left=""),"none"!==t.transform&&(t.transform="",e.transform=""),"auto"!==t.zIndex&&(t.zIndex=""),"0px"!==t.borderRadius&&(t.borderRadius="",t.isolation=""),this.setStyle(),this.transformParallax()},n.prototype.destroy=function(){var t;this.observer&&this.observer.disconnect(),this.wrapper.removeAttribute("style"),this.element.removeAttribute("style"),(t=this.wrapper).replaceWith.apply(t,this.wrapper.childNodes)};var o=function(e,i){if(this.elements=[],!e)throw new Error("Argument 'elements' is null.");var n,o;(this.elements=function(e){return Array.isArray(e)?e:"string"==typeof e?t(document.querySelectorAll(e)):e instanceof HTMLElement?[e]:e instanceof NodeList||e instanceof HTMLCollection?t(e):[e]}(e),this.options=i,this.instances=[],this.externalRAF=!(!this.options||!this.options.externalRAF)&&this.options.externalRAF,this.onResizeEvent=this.resize.bind(this),this.isInit=!1,n="undefined"!=typeof Promise&&-1!==Promise.toString().indexOf("[native code]"),o="undefined"!=typeof Element&&Element.prototype.closest,n&&o&&"IntersectionObserver"in window)&&this.init()};return o.prototype.init=function(){var t=this;this.isInit||(this.instances=this.elements.map((function(e){return new n(e,t.options)})),this.externalRAF||this.animate(),this.addEventListeners(),this.isInit=!0)},o.prototype.animate=function(){this.instances.forEach((function(t){t.animate()})),this.externalRAF||(this.requestId=window.requestAnimationFrame(this.animate.bind(this)))},o.prototype.cancel=function(){this.requestId&&window.cancelAnimationFrame(this.requestId)},o.prototype.reset=function(){this.instances.forEach((function(t){t.reset()}))},o.prototype.resize=function(){clearTimeout(this.timer),this.timer=window.setTimeout(this.reset.bind(this),500),this.reset.bind(this)},o.prototype.addEventListeners=function(){navigator.userAgent.match(/(iPhone|iPad|iPod|Android)/)?window.addEventListener("orientationchange",this.onResizeEvent):window.addEventListener("resize",this.onResizeEvent)},o.prototype.destroy=function(){this.cancel(),window.removeEventListener("resize",this.onResizeEvent),window.removeEventListener("orientationchange",this.onResizeEvent),this.instances.forEach((function(t){t.destroy()})),this.isInit=!1},o})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Ukiyo=e()}(this,(function(){"use strict";var t=function(t){return Array.prototype.slice.call(t)},e=function(){var t=window.navigator.userAgent,e=!!t.match(/iPad/i)||!!t.match(/iPhone/i),i=!!t.match(/WebKit/i);return e&&i&&!t.match(/CriOS/i)},i={scale:1.5,speed:1.5,wrapperClass:null,willChange:!1,externalRAF:!1},n=function(t,e){var n=this;if(this.element=t,this.wrapper=document.createElement("div"),this.options=Object.assign({},i,e),this.updateOptions(),this.vh=document.documentElement.clientHeight,this.isVisible=!1,this.damp=this.calcDamp(document.documentElement.clientWidth),this.elementTagName=this.element.tagName.toLowerCase(),"img"===this.elementTagName){var o=this.element.getAttribute("src");if(!o)return;(async function(t){var e=new Image;return e.src=t,await e.decode(),e})(o).then((function(){n.createParallax()}))}else this.createParallax()};n.prototype.createParallax=function(){this.setStyle(!0),this.wrapElement(),e()||this.createObserver()},n.prototype.updateOptions=function(){var t=this.element.getAttribute("data-u-scale"),e=this.element.getAttribute("data-u-speed"),i=this.element.getAttribute("data-u-willchange");null!==t&&(this.options.scale=Number(t)),null!==e&&(this.options.speed=Number(e)),null!==i&&(this.options.willChange=!0)},n.prototype.setStyle=function(t){void 0===t&&(t=!1);var e=this.element.clientHeight,i=this.element.clientWidth,n=window.getComputedStyle(this.element),o="absolute"===n.position,s=this.wrapper.style,r=this.element.style;this.overflow=Math.floor(10*(e-e*this.options.scale))/10,this.overflowAbs=Math.abs(this.overflow),o&&"0px"!==n.marginRight&&"0px"!==n.marginLeft&&n.marginLeft===n.marginRight&&(s.margin="auto"),"0px"===n.marginTop&&"0px"===n.marginBottom||(s.marginTop=n.marginTop,s.marginBottom=n.marginBottom,r.marginTop="0",r.marginBottom="0"),"auto"!==n.inset&&(s.top=n.top,s.right=n.right,s.bottom=n.bottom,s.left=n.left,r.top="0",r.right="0",r.bottom="0",r.left="0"),"none"!==n.transform&&(s.transform=n.transform),"auto"!==n.zIndex&&(s.zIndex=n.zIndex),s.position=o?"absolute":"relative","auto"!==n.gridArea&&"auto / auto / auto / auto"!==n.gridArea&&(s.gridArea=n.gridArea,r.gridArea="auto"),t&&(s.width="100%",s.overflow="hidden",r.display="block",r.overflow="hidden",r.backfaceVisibility="hidden","0px"!==n.padding&&(r.padding="0"),"img"===this.elementTagName?r.objectFit="cover":"video"!==this.elementTagName&&(r.backgroundPosition="center")),"0px"!==n.borderRadius&&(s.borderRadius=n.borderRadius,s.isolation||(s.isolation="isolate"),"0px"!==n.marginLeft&&(s.marginLeft=n.marginLeft,r.marginLeft="0"),"0px"!==n.marginRight&&(s.marginRight=n.marginRight,r.marginRight="0"),s.width=i+"px"),o&&(s.width=i+"px",r.width="100%"),"none"!==n.maxHeight&&(s.maxHeight=n.maxHeight,r.maxHeight="none"),"0px"!==n.minHeight&&(s.minHeight=n.minHeight,r.minHeight="none"),r.width=i+"px",s.setProperty("height",e+"px","important"),r.setProperty("height",e*this.options.scale+"px","important"),this.wrapperHeight=e},n.prototype.wrapElement=function(){var t=this.element.getAttribute("data-u-wrapper-class")||this.options.wrapperClass;t&&this.wrapper.classList.add(t);var e=this.element.closest("picture");if(null!==e)null!==e.parentNode&&e.parentNode.insertBefore(this.wrapper,e),this.wrapper.appendChild(e);else{var i=this.element.parentNode;null!==i&&i.insertBefore(this.wrapper,this.element),this.wrapper.appendChild(this.element)}},n.prototype.checkVisible=function(){var t=this.wrapper.getBoundingClientRect();0<t.bottom&&t.top<this.vh?this.onEnter():this.onLeave()},n.prototype.createObserver=function(){this.observer=new IntersectionObserver(this.handleIntersect.bind(this),{root:null,rootMargin:"0px",threshold:0}),this.observer.observe(this.wrapper)},n.prototype.handleIntersect=function(t){t[0].isIntersecting?this.onEnter():this.onLeave()},n.prototype.onEnter=function(){var t=this.element.style;this.options.willChange&&"transform"!==t.willChange&&(t.willChange="transform"),this.isVisible=!0},n.prototype.onLeave=function(){var t=this.element.style;this.options.willChange&&"transform"===t.willChange&&(t.willChange=""),this.isVisible=!1},n.prototype.calcTranslateValue=function(){var t=window.pageYOffset;t<0&&(t=0);var e=this.wrapper.getBoundingClientRect().top+t,i=(t+this.vh-e)/((this.vh+this.wrapperHeight)/100),n=Math.min(100,Math.max(0,i))/100,o=this.overflow+this.overflowAbs*n*this.options.speed*this.damp;return Number(o.toFixed(4))},n.prototype.calcDamp=function(t){var e=this.options.scale,i=this.options.speed;if((i>=1.4||e>=1.4)&&t<=1e3){e<1&&(e=1),i<1&&(i=1);var n=1.2-(1-(t/1e3+(3-(e+i)))),o=Math.max(.5,Math.min(1,n));return Math.floor(100*o)/100}return 1},n.prototype.transformParallax=function(){this.element.style.transform="translate3d(0 , "+this.calcTranslateValue()+"px , 0)"},n.prototype.animate=function(){e()&&this.checkVisible(),window.pageYOffset<0||this.isVisible&&this.transformParallax()},n.prototype.reset=function(){this.damp=this.calcDamp(window.innerWidth);var t=this.wrapper.style,e=this.element.style;this.vh=document.documentElement.clientHeight,t.width="",t.position="",t.height="100%",e.width="","img"===this.elementTagName&&"absolute"===t.position&&(t.height="100%"),""===t.gridArea?e.height="":e.height="100%","0px"!==t.margin&&(t.margin="",e.margin=""),"auto"!==t.inset&&(t.top="",t.right="",t.bottom="",t.left="",e.top="",e.right="",e.bottom="",e.left=""),"none"!==t.transform&&(t.transform="",e.transform=""),"auto"!==t.zIndex&&(t.zIndex=""),"0px"!==t.borderRadius&&(t.borderRadius="",t.isolation=""),this.setStyle(),this.transformParallax()},n.prototype.destroy=function(){var t;this.observer&&this.observer.disconnect(),this.wrapper.removeAttribute("style"),this.element.removeAttribute("style"),(t=this.wrapper).replaceWith.apply(t,this.wrapper.childNodes)};var o=function(e,i){if(this.elements=[],!e)throw new Error("Argument 'elements' is null.");var n,o;(this.elements=function(e){return Array.isArray(e)?e:"string"==typeof e?t(document.querySelectorAll(e)):e instanceof HTMLElement?[e]:e instanceof NodeList||e instanceof HTMLCollection?t(e):[e]}(e),this.options=i,this.instances=[],this.externalRAF=!(!this.options||!this.options.externalRAF)&&this.options.externalRAF,this.onResizeEvent=this.resize.bind(this),this.isInit=!1,n="undefined"!=typeof Promise&&-1!==Promise.toString().indexOf("[native code]"),o="undefined"!=typeof Element&&Element.prototype.closest,n&&o&&"IntersectionObserver"in window)&&this.init()};return o.prototype.init=function(){var t=this;this.isInit||(this.instances=this.elements.map((function(e){return new n(e,t.options)})),this.externalRAF||this.animate(),this.addEventListeners(),this.isInit=!0)},o.prototype.animate=function(){this.instances.forEach((function(t){t.animate()})),this.externalRAF||(this.requestId=window.requestAnimationFrame(this.animate.bind(this)))},o.prototype.cancel=function(){this.requestId&&window.cancelAnimationFrame(this.requestId)},o.prototype.reset=function(){this.instances.forEach((function(t){t.reset()}))},o.prototype.resize=function(){clearTimeout(this.timer),this.timer=window.setTimeout(this.reset.bind(this),500),this.reset.bind(this)},o.prototype.addEventListeners=function(){navigator.userAgent.match(/(iPhone|iPad|iPod|Android)/)?window.addEventListener("orientationchange",this.onResizeEvent):window.addEventListener("resize",this.onResizeEvent)},o.prototype.destroy=function(){this.cancel(),window.removeEventListener("resize",this.onResizeEvent),window.removeEventListener("orientationchange",this.onResizeEvent),this.instances.forEach((function(t){t.destroy()})),this.isInit=!1},o})); |
{ | ||
"name": "ukiyojs", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Modern parallax library for picture elements and any images", | ||
@@ -5,0 +5,0 @@ "homepage": "https://yitengjun.github.io/ukiyo-js/", |
@@ -1,2 +0,2 @@ | ||
import pluginTypescript from "@rollup/plugin-typescript"; | ||
import pluginTypescript from '@rollup/plugin-typescript'; | ||
import buble from '@rollup/plugin-buble'; | ||
@@ -11,4 +11,4 @@ import terser from '@rollup/plugin-terser'; | ||
transforms: { | ||
asyncAwait: false | ||
} | ||
asyncAwait: false, | ||
}, | ||
}; | ||
@@ -18,7 +18,8 @@ | ||
input: './src/ukiyo.ts', | ||
output: [{ | ||
output: [ | ||
{ | ||
sourcemap: false, | ||
file: './dist/ukiyo.min.js', | ||
format: 'umd', | ||
name: 'Ukiyo' | ||
name: 'Ukiyo', | ||
}, | ||
@@ -28,3 +29,3 @@ { | ||
format: 'umd', | ||
name: 'Ukiyo' | ||
name: 'Ukiyo', | ||
}, | ||
@@ -34,4 +35,4 @@ { | ||
format: 'umd', | ||
name: 'Ukiyo' | ||
} | ||
name: 'Ukiyo', | ||
}, | ||
], | ||
@@ -41,7 +42,7 @@ plugins: [ | ||
sourceMap: !production, | ||
inlineSources: !production | ||
inlineSources: !production, | ||
}), | ||
buble(bubleOptions), | ||
terser(), | ||
] | ||
], | ||
}; |
@@ -64,6 +64,9 @@ import type { UkiyoOptions } from '../types/index'; | ||
const elementOptionSpeed = this.element.getAttribute('data-u-speed'); | ||
const elementOptionWillChange = this.element.getAttribute('data-u-willchange'); | ||
const elementOptionWillChange = | ||
this.element.getAttribute('data-u-willchange'); | ||
if (elementOptionScale !== null) this.options.scale = Number(elementOptionScale); | ||
if (elementOptionSpeed !== null) this.options.speed = Number(elementOptionSpeed); | ||
if (elementOptionScale !== null) | ||
this.options.scale = Number(elementOptionScale); | ||
if (elementOptionSpeed !== null) | ||
this.options.speed = Number(elementOptionSpeed); | ||
if (elementOptionWillChange !== null) this.options.willChange = true; | ||
@@ -84,7 +87,14 @@ } | ||
// Difference between the height of the element and the wrapper | ||
this.overflow = Math.floor((elementHeight - elementHeight * this.options.scale) * 10) / 10; | ||
this.overflow = | ||
Math.floor((elementHeight - elementHeight * this.options.scale) * 10) / | ||
10; | ||
this.overflowAbs = Math.abs(this.overflow); | ||
// When using both margin: auto and position: absolute | ||
if (isPositionAbsolute && style.marginRight !== '0px' && style.marginLeft !== '0px' && style.marginLeft === style.marginRight) { | ||
if ( | ||
isPositionAbsolute && | ||
style.marginRight !== '0px' && | ||
style.marginLeft !== '0px' && | ||
style.marginLeft === style.marginRight | ||
) { | ||
wrapperStyle.margin = 'auto'; | ||
@@ -121,3 +131,5 @@ } | ||
const hasGrid = style.gridArea !== 'auto' && style.gridArea !== 'auto / auto / auto / auto'; | ||
const hasGrid = | ||
style.gridArea !== 'auto' && | ||
style.gridArea !== 'auto / auto / auto / auto'; | ||
if (hasGrid) { | ||
@@ -164,3 +176,2 @@ wrapperStyle.gridArea = style.gridArea; | ||
wrapperStyle.width = elementWidth + 'px'; | ||
elementStyle.width = elementWidth + 'px'; | ||
} | ||
@@ -172,2 +183,3 @@ | ||
} | ||
if (style.maxHeight !== 'none') { | ||
@@ -182,5 +194,11 @@ wrapperStyle.maxHeight = style.maxHeight; | ||
wrapperStyle.height = elementHeight + 'px'; | ||
elementStyle.height = elementHeight * this.options.scale + 'px'; | ||
elementStyle.width = elementWidth + 'px'; | ||
wrapperStyle.setProperty('height', elementHeight + 'px', 'important'); | ||
elementStyle.setProperty( | ||
'height', | ||
elementHeight * this.options.scale + 'px', | ||
'important', | ||
); | ||
this.wrapperHeight = elementHeight; | ||
@@ -193,4 +211,6 @@ } | ||
private wrapElement(): void { | ||
const elementOptionWrapperClass: string | null | undefined = this.element.getAttribute('data-u-wrapper-class'); | ||
const customClass: string | null = elementOptionWrapperClass || this.options.wrapperClass; | ||
const elementOptionWrapperClass: string | null | undefined = | ||
this.element.getAttribute('data-u-wrapper-class'); | ||
const customClass: string | null = | ||
elementOptionWrapperClass || this.options.wrapperClass; | ||
@@ -240,3 +260,6 @@ if (customClass) { | ||
this.observer = new IntersectionObserver(this.handleIntersect.bind(this), options); | ||
this.observer = new IntersectionObserver( | ||
this.handleIntersect.bind(this), | ||
options, | ||
); | ||
this.observer.observe(this.wrapper); | ||
@@ -285,10 +308,12 @@ } | ||
const elementOffsetTop = this.wrapper.getBoundingClientRect().top + scrollTop; | ||
const elementOffsetTop = | ||
this.wrapper.getBoundingClientRect().top + scrollTop; | ||
const distance = scrollTop + this.vh - elementOffsetTop; | ||
const percentageDistance = distance / ((this.vh + this.wrapperHeight!) / 100); | ||
const percentageDistance = | ||
distance / ((this.vh + this.wrapperHeight!) / 100); | ||
const percentage = Math.min(100, Math.max(0, percentageDistance)) / 100; | ||
const translateValue = this.overflow! + this.overflowAbs! * percentage * this.options.speed * this.damp; | ||
const translateValue = | ||
this.overflow! + | ||
this.overflowAbs! * percentage * this.options.speed * this.damp; | ||
@@ -295,0 +320,0 @@ return Number(translateValue.toFixed(4)); |
@@ -24,3 +24,6 @@ import { isSupportedBrowser, getElements } from './utils'; | ||
this.instances = []; | ||
this.externalRAF = this.options && this.options.externalRAF ? this.options.externalRAF : false; | ||
this.externalRAF = | ||
this.options && this.options.externalRAF | ||
? this.options.externalRAF | ||
: false; | ||
this.onResizeEvent = this.resize.bind(this); | ||
@@ -41,3 +44,5 @@ this.isInit = false; | ||
// Create parallax | ||
this.instances = this.elements.map((element: HTMLElement) => new Parallax(element, this.options)); | ||
this.instances = this.elements.map( | ||
(element: HTMLElement) => new Parallax(element, this.options), | ||
); | ||
@@ -44,0 +49,0 @@ if (!this.externalRAF) { |
@@ -7,3 +7,5 @@ import type { TElement } from '../types/index'; | ||
export const isSupportedBrowser = (): boolean => { | ||
const promise = typeof Promise !== 'undefined' && Promise.toString().indexOf('[native code]') !== -1; | ||
const promise = | ||
typeof Promise !== 'undefined' && | ||
Promise.toString().indexOf('[native code]') !== -1; | ||
const closest = typeof Element !== 'undefined' && Element.prototype.closest; | ||
@@ -36,3 +38,4 @@ | ||
if (Array.isArray(elements)) return elements; | ||
if (typeof elements === 'string') return convertToArray(document.querySelectorAll(elements)); | ||
if (typeof elements === 'string') | ||
return convertToArray(document.querySelectorAll(elements)); | ||
if (elements instanceof HTMLElement) return [elements]; | ||
@@ -39,0 +42,0 @@ if (elements instanceof NodeList) return convertToArray(elements); |
@@ -1,2 +0,7 @@ | ||
export type TElement = string | HTMLElement | HTMLElement[] | NodeList | HTMLCollection; | ||
export type TElement = | ||
| string | ||
| HTMLElement | ||
| HTMLElement[] | ||
| NodeList | ||
| HTMLCollection; | ||
@@ -3,0 +8,0 @@ /** |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
35128
675
0