you-be-my-sun
v1.0.1
Published
Make one DOM element hug another while staying closest to page center
Downloads
3
Maintainers
Readme
you-be-my-sun
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