-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
673 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const elementItems = [ | ||
{ text: 'requestAnimationFrame', link: '/element/request-animation-frame' }, | ||
{ text: 'cancelAnimationFrame', link: '/element/cancel-animation-frame' }, | ||
{ text: 'raf', link: '/element/raf' }, | ||
{ text: 'doubleRaf', link: '/element/double-raf' }, | ||
{ text: 'getStyle', link: '/element/get-style' }, | ||
{ text: 'getRect', link: '/element/get-rect' }, | ||
{ text: 'inViewport', link: '/element/in-viewport' }, | ||
{ text: 'getParentScroller', link: '/element/get-parent-scroller' }, | ||
{ text: 'getAllParentScroller', link: '/element/get-all-parent-scroller' }, | ||
{ text: 'preventDefault', link: '/element/prevent-default' }, | ||
{ text: 'getScrollTop', link: '/element/get-scroll-top' }, | ||
{ text: 'getScrollLeft', link: '/element/get-scroll-left' }, | ||
{ text: 'classes', link: '/element/classes' }, | ||
{ text: 'createNamespaceFn', link: '/element/create-namespace-fn' }, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# cancelAnimationFrame | ||
|
||
Cancels a `requestAnimationFrame` request using the provided handle, with a fallback to `clearTimeout`. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { cancelAnimationFrame } from 'rattail' | ||
|
||
const handle = requestAnimationFrame(() => {}) | ||
cancelAnimationFrame(handle) | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| -------- | -------- | -------- | | ||
| `handle` | `number` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| ------ | | ||
| `void` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# classes | ||
|
||
Generates a list of class names based on a given condition or directly returns class names. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { classes } from 'rattail' | ||
|
||
const classList = classes('active', [true, 'visible', 'hidden']) | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| --------- | --------- | -------- | | ||
| `classes` | `Classes` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| ------- | | ||
| `any[]` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# createNamespaceFn | ||
|
||
Creates a namespace function that allows BEM-style naming of components and classes. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { createNamespaceFn } from 'rattail' | ||
|
||
const ns = createNamespaceFn('my-app') | ||
const bem = ns('button') | ||
console.log(bem.n('--active')) | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| ----------- | -------- | -------- | | ||
| `namespace` | `string` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| -------------------------------------------------- | | ||
| `{ name: string; n: Function; classes: Function }` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# doubleRaf | ||
|
||
Creates a Promise-based double `requestAnimationFrame` that resolves after two frames. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { doubleRaf } from 'rattail' | ||
|
||
doubleRaf().then(() => { | ||
console.log('Two frames later') | ||
}) | ||
``` | ||
|
||
### Return | ||
|
||
| Type | | ||
| --------------- | | ||
| `Promise<void>` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# getAllParentScroller | ||
|
||
Retrieves all scrollable ancestor elements of an element in an array, including the `window` as the last item. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { getAllParentScroller } from 'rattail' | ||
|
||
const scrollers = getAllParentScroller(document.querySelector('div')) | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| ---- | ------------- | -------- | | ||
| `el` | `HTMLElement` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| ------------------------------ | | ||
| `Array<HTMLElement \| Window>` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# getParentScroller | ||
|
||
Finds the closest scrollable ancestor of an element. If no scrollable ancestor is found, returns the `window`. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { getParentScroller } from 'rattail' | ||
|
||
const scroller = getParentScroller(document.querySelector('div')) | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| ---- | ------------- | -------- | | ||
| `el` | `HTMLElement` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| ----------------------- | | ||
| `HTMLElement \| Window` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# getRect | ||
|
||
Gets the dimensions and position of an element or window as a `DOMRect` object. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { getRect } from 'rattail' | ||
|
||
const rect = getRect(document.querySelector('div')) | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| --------- | --------- | -------- | | ||
| `element` | `Element` | `Window` | | ||
|
||
### Return | ||
|
||
| Type | | ||
| --------- | | ||
| `DOMRect` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# getScrollLeft | ||
|
||
Gets the horizontal scroll position of an element or window. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { getScrollLeft } from 'rattail' | ||
|
||
const scrollLeft = getScrollLeft(window) | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| --------- | ------------------- | -------- | | ||
| `element` | `Element \| Window` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| -------- | | ||
| `number` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# getScrollTop | ||
|
||
Gets the vertical scroll position of an element or window. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { getScrollTop } from 'rattail' | ||
|
||
const scrollTop = getScrollTop(window) | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| --------- | ------------------- | -------- | | ||
| `element` | `Element \| Window` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| -------- | | ||
| `number` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# getStyle | ||
|
||
Retrieves computed CSS styles for a given DOM element. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { getStyle } from 'rattail' | ||
|
||
const elementStyle = getStyle(document.querySelector('div')) | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| --------- | --------- | -------- | | ||
| `element` | `Element` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| --------------------- | | ||
| `CSSStyleDeclaration` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# inViewport | ||
|
||
Determines if an element is visible within the viewport. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { inViewport } from 'rattail' | ||
|
||
const isVisible = inViewport(document.querySelector('div')) | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| --------- | ------------- | -------- | | ||
| `element` | `HTMLElement` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| --------- | | ||
| `boolean` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# preventDefault | ||
|
||
Prevents the default action of an event if it is cancelable. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { preventDefault } from 'rattail' | ||
|
||
document.addEventListener('click', preventDefault) | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| ------- | ------- | -------- | | ||
| `event` | `Event` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| ------ | | ||
| `void` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# raf | ||
|
||
Creates a Promise-based `requestAnimationFrame` that resolves on the next frame. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { raf } from 'rattail' | ||
|
||
raf().then(() => { | ||
console.log('Next animation frame') | ||
}) | ||
``` | ||
|
||
### Return | ||
|
||
| Type | | ||
| --------------- | | ||
| `Promise<void>` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# requestAnimationFrame | ||
|
||
Provides a cross-browser compatible `requestAnimationFrame` function, with a fallback to `setTimeout`. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { requestAnimationFrame } from 'rattail' | ||
|
||
requestAnimationFrame(() => { | ||
console.log('Frame requested') | ||
}) | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| ---- | ---------------------- | -------- | | ||
| `fn` | `FrameRequestCallback` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| -------- | | ||
| `number` | |
Oops, something went wrong.