1.0.1 • Published 7 years ago

you-be-my-sun v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

you-be-my-sun NPM version js-standard-style

Make one DOM element hug another while staying closest to page center

install

$ npm install --save you-be-my-sun

api

  • sunEl (DOM Element - required - Element to gravitate around)
  • earthEl (DOM Element - required - Element that will gravitate)
  • fluidity (Number - optional default 30 - Steps (in px) to evaluate positioning)

usage

'use strict'

// Setup
import gravity from 'you-be-my-sun'
const sun = document.getElementById('sun')
const earth = document.getElementById('earth')

// Main
function positionEarth () {
  let { x, y } = gravity(sun, earth, 1)
  earth.style.left = `${x}px`
  earth.style.top = `${y}px`
}

positionEarth()

License

MIT © Andrew Carpenter