Skip to content

How to write a reusable fade in include some params #144

@rain-sc

Description

@rain-sc
// ~/utils/motion
type SlideInDirection = 'left' | 'right' | 'up' | 'down'
type SlideInType = 'tween' | 'spring' | 'keyframes' | 'inertia'

export const fadeInVariants = (direction:SlideInDirection, type:SlideInType, delay:number, duration:number) => ({
  initial: {
    x: direction === 'left' ? 100 : direction === 'right' ? -100 : 0,
    y: direction === 'up' ? 100 : direction === 'down' ? -100 : 0,
    opacity: 0
  },
  visible: {
    x: 0,
    y: 0,
    opacity: 1,
    transition: {
      type,
      delay,
      duration,
      ease: 'easeOut'
    }
  }
})

// index.page
import { fadeInVariants } from '@/utils/motion'

<div v-motion="fadeInVariants('right', 'tween', 0.2, 1)">
move
</div>

it's not working !! How to pass argument to use this. is factible?

solved: fadeInVariants('right', 'tween', 200, 1000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions