https://github.com/matmanjs/select-element-by-mouse
通过鼠标选择 html 上的元素
https://github.com/matmanjs/select-element-by-mouse
Last synced: 3 months ago
JSON representation
通过鼠标选择 html 上的元素
- Host: GitHub
- URL: https://github.com/matmanjs/select-element-by-mouse
- Owner: matmanjs
- License: mit
- Created: 2021-04-27T11:25:08.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-28T09:53:09.000Z (about 4 years ago)
- Last Synced: 2025-03-18T13:49:12.396Z (3 months ago)
- Language: TypeScript
- Size: 1.32 MB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# select-element-by-mouse
通过鼠标选择 html 上的元素。

## 使用说明
安装:
```
$ npm install select-element-by-mouse --save
```使用举例,更多细节请参考 [demo](./demo):
```js
const { EVENT_NAME, SelectElement } = require('select-element-by-mouse');const selectElement = new SelectElement();
selectElement.on(EVENT_NAME.INIT, () => {
console.log('--init--');
});selectElement.on(EVENT_NAME.DESTROY, () => {
console.log('--destroy--');
});selectElement.on(EVENT_NAME.MOUSE_MOVE, (el) => {
console.log('--mouse move--', el);
});selectElement.on(EVENT_NAME.MOUSE_MOVE, (el) => {
console.log('--mouse move--', el);
});selectElement.on(EVENT_NAME.CLICK, (el) => {
console.log('--click--', el);
});selectElement.on(EVENT_NAME.BLUR, () => {
console.log('--blur--');
});// 初始化
selectElement.init();setTimeout(() => {
// 销毁
selectElement.destroy();
}, 5000);
```## API
### SelectElement
#### init()
初始化。
#### destroy()
销毁。
#### on(eventName: string, handler: (el?: HTMLElement) => any)
监听事件。
### EVENT_NAME
事件名字。
```js
export const EVENT_NAME = {
INIT: 'INIT',
DESTROY: 'DESTROY',
MOUSE_MOVE: 'MOUSE_MOVE',
BLUR: 'BLUR',
CLICK: 'CLICK'
};
```