@zcorky/dom
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

dom

NPM version Dependencies Build Status license issues

Dom utils

Install

$ npm install @zcorky/dom

Usage

import {
  $,
  setStyle, setStyles,
  addEvent, addEvents,
  removeEvent, removeEvents,
  onTap,
  getClientXY,
} from '@zcorky/dom';

// 1 get element, remove jquery
const $element = $('#root') // powered by document.querySelector

// 2 set style(s)
setStyle($element, 'width', 10);
setStyle($element, 'width', '100px');
setStyle($element, 'zIndex', 10);
setStyle($element, 'transform', 'translate3d(10, 10, 0)');
// or batch
setStyles($element, {
  'width': 10,
  'zIndex': 10,
  'transform': 'translate3d(10, 10, 0)',
});

// 3 add/remove event
const handler = event => { /* do something */ }
addEvent($element, 'click', handler);
addEvent($element, 'tap', handler); // support simple tap event for mobile
// = onTap($element, handler);
// or batch
addEvents($element, ['click', 'tap'], handler);

// 4 get position
// 4.1 MouseEvent | TouchEvent event position (x, y) => (clientX, clientY)
getClientXY(event); // { clientX, clientY }

Dependents (2)

Package Sidebar

Install

npm i @zcorky/dom

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

8.93 kB

Total Files

13

Last publish

Collaborators

  • uniquecolesmith