Coder Social home page Coder Social logo

frankiez / moto.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tuia-fed/moto.js

0.0 0.0 0.0 691 KB

A light motion library with curvilinear support.

Home Page: https://tuia-fed.github.io/moto-website

License: ISC License

JavaScript 82.55% CSS 17.45%

moto.js's Introduction

moto.js

A light motion library with curvilinear support, inspired by Popmotion.

npm version npm downloads

Usage

npm i @tuia/moto.js

Documents

API

Examples

tween

tween

import {tween} from '@tuia/moto.js'

tween({
  from: {x: 0, radius: 0, opacity: 1},
  to: {x: 200, radius: 25, opacity: .5},
  duration: 3,
  yoyo: Infinity
}).start(v => {
  target.style.transform = `translateX(${v.x}px)`
  target.style.borderRadius = `${v.radius}px`
  target.style.opacity = `${v.opacity}`
})

chain

chain

import {chain, tween} from '@tuia/moto.js'

chain(
  tween({
    from: {x: 0, radius: 25},
    to: {x: 200, radius: 0}
  }),
  tween({
    from: {x: 0, radius: 0, g: 204, b: 51},
    to: {x: -200, radius: 25, g: 51, b: 204}
  })
).start(v => {
  let target = v.g  ? targetA : targetB
  target.css({
    transform: `translateX(${v.x}px)`,
    borderRadius: `${v.radius}px`,
    backgroundColor: v.g ? `rgb(255, ${v.g}, ${v.b})` : '#fc3'
  })
})

composite

composite

import {curve, composite} from '@tuia/moto.js'

composite({
  position: curve.cubicBezier({
    points: this.points,
    duration: .6
  }),

  color: tween({
    from: {g: 204, b: 51},
    to: {g: 51, b: 204},
    duration: .6
  })
}).start(v => {
  const
    target = this.$refs.target,
    dot = document.createElement('i')
  dot.classList.add('dot')
  target.css({
    backgroundColor: `rgb(255, ${v.color.g}, ${v.color.b})`
  })
  dot.style.top = target.style.top = `${v.position.y}px`
  dot.style.left = target.style.left = `${v.position.x}px`

  target.parentElement.appendChild(dot)
})

bezier

bezier

import {curve} from '@tuia/moto.js'

curve.bezier({
  points: [
    {x: 50, y: 50},
    {x: 150, y: 150},
    {x: 250, y: 50}
  ],
  duration: 3
}).start(v => {
  const dot = document.createElement('i')
  dot.classList.add('dot')
  dot.style.top = target.style.top = `${v.y}px`
  dot.style.left = target.style.left = `${v.x}px`
  target.parentElement.appendChild(dot)
})

cubicBezier

cubicBezier

import {curve} from '@tuia/moto.js'

curve.cubicBezier({
  points: [
    {x: 50, y: 50},
    {x: 100, y: 150},
    {x: 300, y: 50},
    {x: 350, y: 150}
  ]
}).start(v => {
  const dot = document.createElement('i')
  dot.classList.add('dot')
  dot.style.top = target.style.top = `${v.y}px`
  dot.style.left = target.style.left = `${v.x}px`
  target.parentElement.appendChild(dot)
})

catmullRom

catmullRom

import {curve} from '@tuia/moto.js'

curve.catmullRom({
  points: [
    {x: 50, y: 50},
    {x: 100, y: 150},
    {x: 200, y: 100},
    {x: 300, y: 50},
    {x: 350, y: 150}
  ]
}).start(v => {
  const dot = document.createElement('i')
  dot.classList.add('dot')
  dot.style.top = target.style.top = `${v.y}px`
  dot.style.left = target.style.left = `${v.x}px`
  target.parentElement.appendChild(dot)
})

moto.js's People

Contributors

yelingxiao avatar yrzhaoweb avatar

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.