Giter Site home page Giter Site logo

React Integration about anime HOT 9 CLOSED

juliangarnier avatar juliangarnier commented on May 3, 2024
React Integration

from anime.

Comments (9)

muratgozel avatar muratgozel commented on May 3, 2024 9

This may be helpful. It is a demonstration of button hover effect.

import anime from 'animejs'
...
const JoinWaitlistButton = ({ href, title }) => {
  return(
    <div>
      <a
        href={ href }
        onMouseOver={e => {
          anime({
            targets: e.currentTarget,
            backgroundPositionX: '10px',
            scale: {
              value: 1.05,
              delay: 300,
              duration: 500
            }
          })
        }}
        onMouseOut={e => {
          anime({
            targets: e.currentTarget,
            backgroundPositionX: '0px',
            scale: {
              value: 1,
              delay: 300,
              duration: 500
            }
          })
        }}>
        { title }
      </a>
    </div>
  )
}

from anime.

fcor avatar fcor commented on May 3, 2024 5

Another example of anime.js in react without any other libraries, just lifecycles:

import React, { Component } from 'react'
import anime from 'animejs'

class Animated extends Component {
  componentDidMount(){
    anime({
        targets: '.anim',
        translateX: [
            { value: 100, duration: 1200 },
            { value: 0, duration: 800 }
        ],
        rotate: '1turn',
        backgroundColor: '#FFF',
        duration: 2000,
        loop: true
    });
  }
  render() {
    return(
      <div class="anim">
       Here goes the element you want to animate!
      </div>
    )
  }
}

export default Animated

from anime.

rohan-deshpande avatar rohan-deshpande commented on May 3, 2024

You can easily integrate it with React by using refs and something like ReactDOM.findDOMNode(this.refs.animeTarget). Anime's targets prop takes DOM elements and that's exactly what you pass it if you get the target via findDOMNode.

If you want to animate multiple things you might want to namespace your refs and then store them in arrays to pass to your anime constructor.

from anime.

kennetpostigo avatar kennetpostigo commented on May 3, 2024

Couldn't you also make anime a component? And just wrap the components you want to animate?

from anime.

juliangarnier avatar juliangarnier commented on May 3, 2024

I'm not familiar with React and the virtual dom, but like @rohan-deshpande said, as long as you're using a valid DOM element as a target, it should work.

from anime.

adrianmcli avatar adrianmcli commented on May 3, 2024

Given that React is becoming such a dominant player in frontend web development, I suggest that @muratgozel's example be put on the README somewhere.

from anime.

kennetpostigo avatar kennetpostigo commented on May 3, 2024

@adrianmcli @muratgozel check out react-anime

from anime.

adrianmcli avatar adrianmcli commented on May 3, 2024

@kennetpostigo awesome! thanks for the link. Maybe there should be a link to it on the README then.

from anime.

jduhls avatar jduhls commented on May 3, 2024

An example of updating a javascript object in state inside a class component instead of directly altering the DOM element ref:

const style = this.state.style

animejs({
  targets: style,
  scale: 1.005,
  boxShadow: 8,
  update: a => this.setState({ style })
})

from anime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.