you-be-my-sun

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i you-be-my-sun

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • doesdev