/dom-lib

DOM helper library

Primary LanguageJavaScriptMIT LicenseMIT

dom-lib Travis npm

DOM helper library

安装

npm install dom-lib --save

示例

import { addClass } from 'dom-lib';

API

Class

hasClass: (node: HTMLElement, className: string) => boolean;
addClass: (node: HTMLElement, className: string) => HTMLElement;
removeClass: (node: HTMLElement, className: string) => HTMLElement;
toggleClass: (node: HTMLElement, className: string) => HTMLElement;

Style

getStyle: (node: HTMLElement, property: string) => string;
getStyle: (node: HTMLElement) => Object;

removeStyle: (node: HTMLElement, property: string) => void;
removeStyle: (node: HTMLElement, propertys: Array<string>) => void;

addStyle: (node: HTMLElement, property: string, value: string) => void;
addStyle: (node: HTMLElement, style: Object) => void;

Events

on: (target: HTMLElement, eventName: string, listener: Function, capture: boolean = false) => {
  off: Function;
};
off: (target: HTMLElement, eventName: string, listener: Function, capture: boolean = false) =>
  void;

Query

activeElement: () => HTMLElement;
getHeight: (node: HTMLElement, client: HTMLElement) => number;
getWidth: (node: HTMLElement, client: HTMLElement) => number;
getOffset: (node: HTMLElement) => Object;
getOffsetParent: (node: HTMLElement) => Object;
getPosition: (node: HTMLElement, offsetParent) => Object;
getWindow: (node: HTMLElement) => String;
nodeName: (node: HTMLElement) => String;
ownerDocument: (node: HTMLElement) => Object;
ownerWindow: (node: HTMLElement) => Object;
contains: (context: HTMLElement, node: HTMLElement) => boolean;
scrollLeft: (node: HTMLElement) => number;
scrollTop: (node: HTMLElement) => number;

Utils

scrollLeft: (node: HTMLElement, val: number) => void;
scrollTop: (node: HTMLElement, val: number) => void;