iamkevingreen / tackjs

πŸ“Œ A minimal toolkit to pin an element relative to another element.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tackjs

Hyper-minimal toolkit to pin an element relative to another element. Demo here. 518b gzipped.

js-standard-style

Install

npm i tackjs --save

Usage

import { tack } from 'tackjs'

const scope = document.getElementById('scope')
const target = document.getElementById('target')

const pin = tack(target, scope, 'top')

// refresh position
pin.update()

// remove class and transform
pin.destroy()

// can be re-pinned!
pin.update()

Alignment

Tack supports the following coordinates relative to the passed scope element:

  • top
  • bottom
  • left
  • right
  • topLeft
  • topRight
  • bottomLeft
  • bottomRight

Browser Support

TODO, but should work in all evergreen browsers and IE 10+.

Example

To run the example, clone this repo, then:

# move into example dir
cd tackjs/example
# install deps
npm i
# compile JS
npm run js:build # or js:watch
# serve index.html and update with changes
live-server 

MIT License

About

πŸ“Œ A minimal toolkit to pin an element relative to another element.


Languages

Language:JavaScript 53.5%Language:CSS 29.3%Language:HTML 17.2%