Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
fix: remove buggy createRef usage and use querySelector instead as it…
Browse files Browse the repository at this point in the history
…'s more reliable here..
  • Loading branch information
TylerBarnes committed Jun 22, 2020
1 parent 7e6afd5 commit 545068f
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions src/AniLink/Cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,31 @@ export default class Cover extends Component {

this.horizontal = this.horizontal.bind(this)
this.vertical = this.vertical.bind(this)

this.cover = React.createRef()
}

getCoverEl = () => document.querySelector(`.tl-cover-el`)

horizontal = ({ node, props: { length: seconds }, direction }) => {
const directionTo = direction === 'left' ? '-100%' : '100%'
const directionFrom = direction === 'left' ? '100%' : '-100%'

const wait = seconds / 6
const half = (seconds - wait) / 2

return gsap.timeline()
.set(this.cover, { y: 0, x: directionFrom, display: 'block' })
.to(this.cover, {
x: '0%',
const cover = this.getCoverEl()

return gsap
.timeline()
.set(cover, { y: 0, x: directionFrom, display: "block" })
.to(cover, {
x: "0%",
ease: "power1.easeInOut",
duration: half,
})
.set(node, { opacity: 0 })
.to(
this.cover, {
cover,
{
x: directionTo,
ease: "power1.easeInOut",
duration: half,
Expand All @@ -44,16 +48,20 @@ export default class Cover extends Component {
const wait = seconds / 6
const half = (seconds - wait) / 2

return gsap.timeline()
.set(this.cover, { y: directionFrom })
.to(this.cover, {
y: '0%',
const cover = this.getCoverEl()

return gsap
.timeline()
.set(cover, { y: directionFrom })
.to(cover, {
y: "0%",
ease: "power1.easeInOut",
duration: half,
})
.set(node, { opacity: 0 })
.to(
this.cover, {
cover,
{
y: directionTo,
ease: "power1.easeIn",
duration: half,
Expand All @@ -63,8 +71,9 @@ export default class Cover extends Component {
}

moveInDirection = ({ props, direction, node }) => {
if (direction === 'left' || direction === 'right')
if (direction === 'left' || direction === 'right') {
return this.horizontal({ props, direction, node })
}

return this.vertical({ props, direction, node })
}
Expand Down Expand Up @@ -93,21 +102,24 @@ export default class Cover extends Component {
entry={{
delay: length / 2,
}}
{...props}>
{...props}
>
{this.props.children}
</TransitionLink>

<TransitionPortal>
<div
ref={n => (this.cover = n)}
className="tl-cover-el"
style={{
position: 'fixed',
background: this.props.bg || '#4b2571',
position: "fixed",
background: this.props.bg || "#4b2571",
top: 0,
left: 0,
width: '100vw',
height: '100vh',
transform: 'translateY(100%)',
right: 0,
zIndex: 1000,
width: "100vw",
height: "100vh",
transform: "translateY(100%)",
}}
/>
</TransitionPortal>
Expand Down

0 comments on commit 545068f

Please sign in to comment.