Coder Social home page Coder Social logo

flyball's Introduction

flyball

Create flyball animation so easy ๐Ÿ‘

Install

$ npm i flyball --save
# or
$ yarn add flyball

Usage

import flyball from 'flyball'
import 'flyball/dist/flyball.css'

Dom

const from = document.getElementById('from')
const to = document.getElementById('to')

flyball(from, to)

Position

const from = { top: 0, left: 100 }
const to = { top: 100, left: 0 }

flyball(from, to)

Position and dom

const from = { top: 0, left: 100 }
const to = document.getElementById('to')

flyball(from, to)

Development

$ npm run dev

Contributing

  • Fork it! ๐Ÿ˜†
  • Create your feature branch: git checkout -b my-new-feature
  • Commit your changes: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Submit a PR ๐Ÿป

Author

MIT @ Limichange

flyball's People

Contributors

limichange avatar

Stargazers

 avatar

Watchers

 avatar  avatar

flyball's Issues

WIP

function createIcon () {
  const iconDiv = document.createElement('div')
  iconDiv.classList.add('add1Icon')
  document.body.appendChild(iconDiv)
  console.info(iconDiv.clientHeight)
  iconDiv.classList.add('active')
  setTimeout(() => {
    document.body.removeChild(iconDiv)
  }, 2000)
  return iconDiv
}

function getScale () {
  let i = 1
  const viewport = document.querySelector('meta[name="viewport"]')

  if (viewport) {
    const scale = viewport.content.match(/initial-scale=(\d+\.?\d*)/)
    scale && (i = scale[1])
  }

  return i
}

export default function (t, e) {
  if (!e || !t.currentTarget) {
    return Promise.reject(new Error('no params'))
  }

  if (void 0 === e.left || void 0 === e.top) {
    return Promise.reject(new Error('no position'))
  }

  const i = getScale()
  const a = 9 / parseFloat(i)
  const r = t.currentTarget.getBoundingClientRect()
  const s = e
  const flyball = document.createElement('div')
  const inner = document.createElement('div')

  flyball.classList.add('flyball')
  inner.classList.add('inner')
  inner.style.width = 2 * a + 'px'
  inner.style.height = 2 * a + 'px'
  flyball.style.top = r.top + 'px'
  flyball.style.left = r.left + 'px'
  flyball.appendChild(inner)

  document.body.appendChild(flyball)

  const targetPosition = {
    top: s.top - r.top,
    left: s.left - r.left
  }

  console.info(flyball.clientHeight)

  const prefixs = ['-webkit-', '-moz-', '-ms-', '-o-', '']

  prefixs.forEach(function (n) {
    flyball.style.setProperty(n + 'transform', 'translate3d(' + targetPosition.left + 'px, 0, 0)')
    inner.style.setProperty(n + 'transform', 'translate3d(0 ,' + targetPosition.top + 'px, 0)')
  })

  createIcon()

  return new Promise(function (resolve) {
    inner.addEventListener('transitionend', function () {
      document.body.removeChild(flyball)
      resolve(true)
    })
  })
}

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.