-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export animate-on-reveal web-component independently
- Loading branch information
1 parent
21414e0
commit 4d5630b
Showing
8 changed files
with
127 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
const style = ""; | ||
const DEV_COMPONENT_TAG_NAME = "animate-on-reveal"; | ||
const _AnimateOnElementReveal = class _AnimateOnElementReveal2 extends HTMLElement { | ||
constructor() { | ||
super(); | ||
if (!this.firstElementChild) { | ||
return; | ||
} | ||
this.nodeToObserve = this.findObservableNodeFromTree( | ||
this.firstElementChild | ||
); | ||
this.intersectionObserver = new IntersectionObserver( | ||
(entries) => { | ||
entries.forEach((entry) => { | ||
if (entry.isIntersecting) { | ||
this.setAttribute("revealed", ""); | ||
} else { | ||
this.removeAttribute("revealed"); | ||
} | ||
}); | ||
}, | ||
{ threshold: 0.5 } | ||
); | ||
this.style.display = "contents"; | ||
} | ||
static registerSelf() { | ||
if (!window.customElements.get(DEV_COMPONENT_TAG_NAME)) { | ||
window.customElements.define( | ||
DEV_COMPONENT_TAG_NAME, | ||
_AnimateOnElementReveal2 | ||
); | ||
} | ||
} | ||
connectedCallback() { | ||
if (!this.nodeToObserve) { | ||
return; | ||
} | ||
this.nodeToObserve.style.animationPlayState = "paused"; | ||
this.intersectionObserver.observe(this.nodeToObserve); | ||
} | ||
disconnectedCallback() { | ||
this.intersectionObserver.disconnect(); | ||
} | ||
findObservableNodeFromTree(node) { | ||
const style2 = window.getComputedStyle(node); | ||
if (style2.getPropertyValue("display") !== "contents") { | ||
return node; | ||
} | ||
const children = node.children; | ||
for (let i = 0; i < children.length; i++) { | ||
const descendant = this.findObservableNodeFromTree(children[i]); | ||
if (descendant) { | ||
return descendant; | ||
} | ||
} | ||
return null; | ||
} | ||
attributeChangedCallback(name) { | ||
switch (name) { | ||
case "animation": | ||
this.nodeToObserve.style.animationName = this.getAttribute("animation") || ""; | ||
break; | ||
case "duration": | ||
this.nodeToObserve.style.animationDuration = this.getAttribute(name) || "0s"; | ||
break; | ||
case "delay": | ||
this.nodeToObserve.style.animationDelay = this.getAttribute(name) || "0s"; | ||
break; | ||
case "easing": | ||
this.nodeToObserve.style.animationTimingFunction = this.getAttribute(name) || "ease"; | ||
break; | ||
case "iteration": | ||
this.nodeToObserve.style.animationIterationCount = this.getAttribute(name) || "1"; | ||
break; | ||
case "direction": | ||
this.nodeToObserve.style.animationDirection = this.getAttribute(name) || "normal"; | ||
break; | ||
case "revealed": | ||
this.nodeToObserve.style.animationPlayState = this.hasAttribute( | ||
"revealed" | ||
) ? "running" : "paused"; | ||
break; | ||
} | ||
} | ||
}; | ||
_AnimateOnElementReveal.observedAttributes = [ | ||
"animation", | ||
"duration", | ||
"delay", | ||
"direction", | ||
"easing", | ||
"revealed", | ||
"class", | ||
"classname", | ||
"iteration" | ||
]; | ||
let AnimateOnElementReveal = _AnimateOnElementReveal; | ||
AnimateOnElementReveal.registerSelf(); | ||
export { | ||
AnimateOnElementReveal as default | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import './animate-on-reveal/style.css' | ||
export { default as DateTimePrimitive } from './date-time' | ||
export { default as DangerousHTML } from './dangerous-html' | ||
export { default as DataProvider } from './data-provider' | ||
export { default as Repeater } from './repeater' | ||
export { default as CaisyDocumentLink } from './caisy-document-link' | ||
export { default as CMSMixedType } from './cms-mixed-type' | ||
export { default as AnimateOnElementReveal } from './animate-on-reveal' | ||
export { default as DateTimePrimitive } from "./date-time"; | ||
export { default as DangerousHTML } from "./dangerous-html"; | ||
export { default as DataProvider } from "./data-provider"; | ||
export { default as Repeater } from "./repeater"; | ||
export { default as CaisyDocumentLink } from "./caisy-document-link"; | ||
export { default as CMSMixedType } from "./cms-mixed-type"; |
Oops, something went wrong.