Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react'
  2. import { Animate } from 'react-move'
  3.  
  4. const animateOptions = {
  5.   // Set some default data
  6.   default: {
  7.     scale: 0,
  8.     color: 'blue',
  9.     rotate: 0
  10.   },
  11.   // Update your data to whatever you want
  12.   data: {
  13.     scale: Math.random() * 1,
  14.     color: ['red', 'blue', 'yellow'].find((d, i) => i === Math.round(Math.random() * 2)),
  15.     rotate: Math.random() > 0.5 ? 360 : 0
  16.   },
  17.   duration: 800,
  18.   // anything from https://github.com/d3/d3-ease
  19.   easing: 'easeQuadIn'
  20. };
  21.  
  22. <Animate {...animateOptions}>
  23.   {data => { // the child function is passed the current state of the data as an object
  24.     return (
  25.       <div
  26.         style={{
  27.           borderRadius: ((data.rotate / 360) * 100) + 'px',
  28.           transform: `translate(${data.scale * 50}%, ${data.scale * 50}%) scale(${data.scale}) rotate(${data.rotate}deg)`,
  29.           background: data.color
  30.         }}
  31.       >
  32.         {Math.round(data.scale * 100) / 100}
  33.       </div>
  34.     )
  35.   }}
  36. </Animate>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement