mirror of
https://codeberg.org/vlw/elevent.git
synced 2025-09-14 00:23:41 +02:00
doc: add README
This commit is contained in:
parent
ed98dcfec3
commit
fb2b376921
1 changed files with 62 additions and 2 deletions
64
README.md
64
README.md
|
@ -1,3 +1,63 @@
|
|||
# cursor
|
||||
# Elevent
|
||||
|
||||
Cursor is a front-end JavaScript abstraction library for running custom
|
||||
Create callback functions for any [EventTarget](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget) dispatched on HTML elements.
|
||||
|
||||
```js
|
||||
import { Elevent } from "https://cdn.jsdelivr.net/npm/elevent/src/Elevent.mjs"
|
||||
|
||||
new Elevent("click", document.querySelector("#myButton"), () => console.log("Button clicked!")); // console: "Button clicked"
|
||||
```
|
||||
|
||||
# Examples
|
||||
|
||||
## Bind from an HTMLCollection
|
||||
```js
|
||||
new Elevent("click", document.querySelectorAll("button"), (event) => console.log(event)); // console: PointerEvent
|
||||
```
|
||||
|
||||
## Bind with a CSS selector
|
||||
```js
|
||||
// Bind all elements that match the CSS selector string
|
||||
new Elevent("click", ".css-selector", (event, elevent) => console.log(event, elevent)) // console: PointerEvent, Elevent
|
||||
```
|
||||
> New elements added to the DOM with a matching CSS selector will bind automatically
|
||||
|
||||
## Remove event listeners
|
||||
```js
|
||||
const elevent = new Elevent("click", null, () => {}); // Empty Elevent instance
|
||||
|
||||
elevent.remove(document.querySelector("#specialButton")); // Remove a specific HTMLElement if bound
|
||||
elevent.remove(); // Remove ALL currently bound elements
|
||||
```
|
||||
|
||||
## Bind a specific element
|
||||
```js
|
||||
const elevent = new Elevent("click", null, () => {}); // Empty Elevent instance
|
||||
|
||||
elevent.bind(document.querySelector("#bindMe"));
|
||||
```
|
||||
|
||||
# Description
|
||||
|
||||
### `Elevent.constructor`
|
||||
```ts
|
||||
Elevent.constructor(
|
||||
eventType: string | null
|
||||
target: HTMLCollection | HTMLElement | string | null,
|
||||
callback: CallableFunction
|
||||
)
|
||||
```
|
||||
|
||||
### `this.bind()`
|
||||
```ts
|
||||
this.bind(
|
||||
target: HTMLElement
|
||||
)
|
||||
```
|
||||
|
||||
### `this.remove()`
|
||||
```ts
|
||||
this.remove(
|
||||
target?: HTMLElement
|
||||
)
|
||||
```
|
Loading…
Add table
Reference in a new issue