Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/doesdev/you-be-my-sun
Make one DOM element hug another while staying closest to page center
https://github.com/doesdev/you-be-my-sun
Last synced: about 20 hours ago
JSON representation
Make one DOM element hug another while staying closest to page center
- Host: GitHub
- URL: https://github.com/doesdev/you-be-my-sun
- Owner: doesdev
- License: mit
- Created: 2016-12-18T01:46:20.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-27T23:41:35.000Z (over 7 years ago)
- Last Synced: 2024-11-07T11:54:09.572Z (12 days ago)
- Language: JavaScript
- Homepage: https://doesdev.github.io/you-be-my-sun/
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# you-be-my-sun [![NPM version](https://badge.fury.io/js/you-be-my-sun.svg)](https://npmjs.org/package/you-be-my-sun) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) [![Dependency Status](https://dependencyci.com/github/doesdev/you-be-my-sun/badge)](https://dependencyci.com/github/doesdev/you-be-my-sun)
> Make one DOM element hug another while staying closest to page center
## install
```sh
$ 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
```js
'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](https://github.com/doesdev)