Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/okikio/native. An initiative which aims to make it easy to create complex, light-weight, and perfor okikio.github.io/native
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import { Service, animate } from "@okikio/native";
export class IntroAnimation extends Service { public elements: Array<Element>; public rootElement: HTMLElement;
public init() { super.init();
// Elements this.elements = Array.from(document.querySelectorAll('.intro-animation')); }
public newPage() { this.init(); this.prepareToShow(); }
public initEvents() { this.emitter.on("CONTENT_REPLACED", this.newPage, this); this.emitter.on("BEFORE_TRANSITION_IN", this.show, this); }
public stopEvents() { this.emitter.off("CONTENT_REPLACED", this.newPage, this); this.emitter.off("BEFORE_TRANSITION_IN", this.show, this); }
public stop() { requestAnimationFrame(() => { for (let el of this.elements) { (el as HTMLElement).style.opacity = '1'; } });
super.stop(); }
public prepareToShow() { requestAnimationFrame(() => { for (let el of this.elements) { (el as HTMLElement).style.opacity = '0'; } }); }
public async show() { let [anim] = await animate({ target: (this.elements as HTMLElement[]), opacity: [0, 1], delay(i: number) { return 300 * (i + 1); }, onfinish(el: { style: { transform: string; opacity: string; }; }) { el.style.opacity = "1"; }, easing: "ease", duration: 850 }); anim.stop(); return anim; }}