diff --git a/client/src/components/anims/link.jsx b/client/src/components/anims/link.jsx new file mode 100644 index 00000000..f6f9dca3 --- /dev/null +++ b/client/src/components/anims/link.jsx @@ -0,0 +1,77 @@ +const preact = require('preact'); +const { Component } = require('preact'); + +const anime = require('animejs').default; + +const { TIMES } = require('../../constants'); + +class Link extends Component { + constructor() { + super(); + this.animations = []; + } + + render() { + return ( + + + + + + + + + + + + + + + ); + } + + componentDidMount() { + this.animations.push(anime({ + targets: ['#link'], + opacity: [ + { value: 1, delay: TIMES.TARGET_DELAY_MS, duration: 1000 }, + { value: 0, delay: TIMES.TARGET_DURATION_MS * 0.7, duration: TIMES.TARGET_DURATION_MS * 0.2 }, + ], + easing: 'easeInOutSine', + })); + + anime({ + targets: ['#link path'], + strokeDashoffset: [anime.setDashoffset, 0], + duration: TIMES.TARGET_DURATION_MS * 0.8, + delay: TIMES.TARGET_DELAY_MS, + easing: 'easeInOutSine', + }); + } + + // this is necessary because + // skipping / timing / unmounting race conditions + // can cause the animations to cut short, this will ensure the values are reset + // because preact will recycle all these components + componentWillUnmount() { + for (let i = this.animations.length - 1; i >= 0; i--) { + this.animations[i].reset(); + } + } +} + +module.exports = Link;