### Import and initialize ASScroll
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Import ASScroll and create a new instance, then enable it on the window load event. This is the zero-config setup after adding the container attribute.
```javascript
import ASScroll from '@ashthornton/asscroll'
const asscroll = new ASScroll()
window.addEventListener('load', () => {
asscroll.enable()
})
```
--------------------------------
### .containerElement
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Gets the container element that is used for smooth scrolling. This is a read-only property.
```APIDOC
## Property: .containerElement
### Description
Gets the container element that is used for smooth scrolling. This is a read-only property.
### Returns
- `HTMLElement` - The container element.
```
--------------------------------
### HTML container setup for ASScroll
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Add the `asscroll-container` attribute to the parent element of the content to be smooth scrolled. The first child found within will be scrolled by default; both selectors can be changed in the options.
```html
```
--------------------------------
### asscroll.currentPos
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Gets or sets the current scroll position. Setting the position bypasses any lerps.
```APIDOC
## asscroll.currentPos
### Description
Gets or sets the current scroll position. Setting the position bypasses any lerps.
### Parameters
- **scrollPos** (number) - The desired scroll position
### Returns
- **number** - Current scroll position
### Example
```js
asscroll.currentPos = 200
```
```
--------------------------------
### .isScrollJacking
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Gets a boolean indicating whether scroll jacking is enabled. This is a read-only property.
```APIDOC
## Property: .isScrollJacking
### Description
Gets a boolean indicating whether scroll jacking is enabled. This is a read-only property.
### Returns
- `boolean` - `true` if scroll jacking is enabled, `false` otherwise.
```
--------------------------------
### .isHorizontal
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Gets a boolean indicating whether the scroll is horizontal. This is a read-only property.
```APIDOC
## Property: .isHorizontal
### Description
Gets a boolean indicating whether the scroll is horizontal. This is a read-only property.
### Returns
- `boolean` - `true` if horizontal, `false` otherwise.
```
--------------------------------
### .scrollElements
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Gets the array of elements that are scrolled. This is a read-only property.
```APIDOC
## Property: .scrollElements
### Description
Gets the array of elements that are scrolled. This is a read-only property.
### Returns
- `Array` - The array of scroll elements.
```
--------------------------------
### .currentPos
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Gets the current scroll position (the actual position that is currently displayed). This is a read-only property.
```APIDOC
## Property: .currentPos
### Description
Gets the current scroll position (the actual position that is currently displayed). This is a read-only property.
### Returns
- `number` - The current scroll position.
```
--------------------------------
### .targetPos
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Gets the target scroll position (the destination position that the smooth scroll is animating towards). This is a read-only property.
```APIDOC
## Property: .targetPos
### Description
Gets the target scroll position (the destination position that the smooth scroll is animating towards). This is a read-only property.
### Returns
- `number` - The target scroll position.
```
--------------------------------
### .maxScroll
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Gets the maximum scroll position (the maximum value that the scroll can reach). This is a read-only property.
```APIDOC
## Property: .maxScroll
### Description
Gets the maximum scroll position (the maximum value that the scroll can reach). This is a read-only property.
### Returns
- `number` - The maximum scroll position.
```
--------------------------------
### asscroll.isScrollJacking
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Returns whether or not ASScroll is actively transforming the page element(s). For example, would return false if running on a touch device and touchScrollType !== 'transform', or if ASScroll was currently disabled via the .disable() method.
```APIDOC
## asscroll.isScrollJacking
### Description
Returns whether or not ASScroll is actively transforming the page element(s). For example, would return false if running on a touch device and touchScrollType !== 'transform', or if ASScroll was currently disabled via the .disable() method.
### Returns
- **boolean** - The status of actively controlling the page scroll
```
--------------------------------
### new ASScroll([parameters])
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Creates a new ASScroll instance for smooth scrolling. The constructor accepts optional parameters to configure the smooth scroll behavior.
```APIDOC
## Constructor: new ASScroll([parameters])
### Description
Creates a new ASScroll instance for smooth scrolling. The constructor accepts optional parameters to configure the smooth scroll behavior.
### Parameters
- `parameters` (Object) - Optional - Configuration options for the smooth scroll instance.
### Example
```js
const asscroll = new ASScroll()
```
```
--------------------------------
### asscroll.resize([parameters])
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Calls the internal resize callback. Optionally accepts width and height parameters to specify the new window dimensions.
```APIDOC
## asscroll.resize([parameters])
### Description
Calls the internal resize callback.
### Method
resize
### Endpoint
asscroll.resize([parameters])
### Parameters
#### Optional Parameters
- **parameters** (object) - Optional - An object containing width and height.
- **parameters.width** (number) - Optional - Window width.
- **parameters.height** (number) - Optional - Window height.
### Request Example
```js
asscroll.resize({ width: 1024, height: 768 })
```
### Response
No return value.
```
--------------------------------
### new ASScroll([parameters])
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Creates an ASScroll instance. This constructor initializes the smooth scrolling behavior with configurable options for container, scroll elements, easing, touch behavior, and custom scrollbar.
```APIDOC
## new ASScroll([parameters])
### Description
Creates an ASScroll instance.
### Method
Constructor
### Parameters
#### Parameters (Object)
- **containerElement** (string | HTMLElement) - Optional - The selector string for the outer container element, or the element itself. Default: `"[asscroll-container]"`
- **scrollElements** (string | HTMLElement | NodeList) - Optional - The selector string for the elements to scroll, or the elements themselves. Default: `"[asscroll]"`
- **ease** (number) - Optional - The ease amount for the transform lerp. Default: `0.075`
- **touchEase** (number) - Optional - The ease amount for the transform lerp on touch devices. Default: `1`
- **touchScrollType** (string) - Optional - Set the scrolling method on touch devices. Other options are 'transform' and 'scrollTop'. See the [Touch Devices](#touch-devices) section for more info. Default: `"none"`
- **lockIOSBrowserUI** (boolean) - Optional - When using an iOS device and touchScrollType is 'transform', this will change the setup to prevent the browser UI from showing/hiding to stop resize events on scroll. Default: `false`
- **scrollbarEl** (string) - Optional - The selector string for the custom scrollbar element. Default: `".asscrollbar"`
- **scrollbarHandleEl** (string) - Optional - The selector string for the custom scrollbar handle element. Default: `".asscrollbar__handle"`
- **customScrollbar** (boolean) - Optional - Toggle the custom scrollbar. Default: `true`
- **scrollbarStyles** (boolean) - Optional - Include the scrollbar CSS via Javascript. Default: `true`
- **disableNativeScrollbar** (boolean) - Optional - Disable the native browser scrollbar. Default: `true`
- **disableRaf** (boolean) - Optional - Disable internal requestAnimationFrame loop in order to use an external one. Default: `false`
- **disableResize** (boolean) - Optional - Disable internal resize event on the window in order to use an external one. Default: `false`
- **limitLerpRate** (boolean) - Optional - Match lerp speed on >60Hz displays to that of a 60Hz display. Default: `true`
- **blockScrollClass** (string) - Optional - The class to add to elements that should block ASScroll when hovered. Default: `".asscroll-block"`
### Response
#### Success Response
Returns a new ASScroll instance.
```
--------------------------------
### asscroll.onResize() (Deprecated)
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Deprecated method. Use resize() instead.
```APIDOC
## ~~asscroll.onResize()~~ (Deprecated)
### Description
Deprecated. See [resize](#ASScroll+resize).
### Method
N/A (JavaScript method)
### Parameters
None
### Request Example
N/A
### Response
N/A
```
--------------------------------
### .resize([parameters])
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Handles resize events for the smooth scroll instance. This method should be called when the viewport or container size changes.
```APIDOC
## Method: .resize([parameters])
### Description
Handles resize events for the smooth scroll instance. This method should be called when the viewport or container size changes.
### Parameters
- `parameters` (Object) - Optional - Configuration options for resizing.
### Example
```js
asscroll.resize()
```
```
--------------------------------
### .enable([parameters])
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Enables the smooth scroll functionality. This method should be called after the page has loaded to activate the smooth scrolling behavior.
```APIDOC
## Method: .enable([parameters])
### Description
Enables the smooth scroll functionality. This method should be called after the page has loaded to activate the smooth scrolling behavior.
### Parameters
- `parameters` (Object) - Optional - Configuration options for enabling.
### Example
```js
asscroll.enable()
```
```
--------------------------------
### .on(eventName, callback)
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Registers an event listener for a specified event. The callback will be invoked when the event is triggered.
```APIDOC
## Method: .on(eventName, callback)
### Description
Registers an event listener for a specified event. The callback will be invoked when the event is triggered.
### Parameters
- `eventName` (string) - Required - The name of the event to listen for.
- `callback` (function) - Required - The function to call when the event is triggered.
### Example
```js
asscroll.on('scroll', () => {})
```
```
--------------------------------
### Import ASScroll CSS
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Import the CSS necessary to hide the native scrollbar. This avoids a flash of the native scrollbar before JS loads.
```CSS
@import '~@ashthornton/asscroll/css'
```
--------------------------------
### asscroll.enable([parameters])
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Enables ASScroll. Optionally specify new scroll elements, reset or restore scroll position, or toggle horizontal scrolling.
```APIDOC
## asscroll.enable([parameters])
### Description
Enables ASScroll. Optionally specify new scroll elements, reset or restore scroll position, or toggle horizontal scrolling.
### Method
enable
### Parameters
#### Optional Parameters
- **parameters** (object) - Optional - Configuration object
- **parameters.newScrollElements** (boolean | NodeList | HTMLElement) - Optional - Default: false - Specify the new element(s) that should be scrolled
- **parameters.reset** (boolean) - Optional - Default: false - Reset the scroll position to 0
- **parameters.restore** (boolean) - Optional - Default: false - Restore the scroll position to where it was when disable() was called
- **parameters.horizontalScroll** (boolean) - Optional - Default: false - Toggle horizontal scrolling
### Request Example
```js
asscroll.enable({ newScrollElements: document.querySelector('.page'), reset: true })
```
### Response
No response value is documented.
```
--------------------------------
### .scrollTo(targetPos, [emitEvent])
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Smoothly scrolls to a specified target position. Optionally, an event can be emitted when the scroll completes.
```APIDOC
## Method: .scrollTo(targetPos, [emitEvent])
### Description
Smoothly scrolls to a specified target position. Optionally, an event can be emitted when the scroll completes.
### Parameters
- `targetPos` (number) - Required - The target scroll position.
- `emitEvent` (boolean) - Optional - Whether to emit an event after scrolling.
### Example
```js
asscroll.scrollTo(500)
```
```
--------------------------------
### asscroll.onRaf() (Deprecated)
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Deprecated method. Use update() instead.
```APIDOC
## ~~asscroll.onRaf()~~ (Deprecated)
### Description
Deprecated. See [update](#ASScroll+update).
### Method
N/A (JavaScript method)
### Parameters
None
### Request Example
N/A
### Response
N/A
```
--------------------------------
### asscroll.on(eventName, callback)
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Adds an event listener for a specified event. The callback is executed when the event fires.
```APIDOC
## asscroll.on(eventName, callback)
### Description
Adds an event listener for a specified event. The callback is executed when the event fires.
### Method
on
### Endpoint
asscroll.on(eventName, callback)
### Parameters
- **eventName** (string) - Required - Name of the event you wish to listen for.
- **callback** (function) - Required - Callback function that should be executed when the event fires.
### Request Example
```js
asscroll.on('scroll', scrollPos => console.log(scrollPos))
```
### Response
No return value.
```
--------------------------------
### Enable ASScroll and restore previous position
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Enables ASScroll and restores the scroll position to where it was when disable() was called. The 'restore' parameter defaults to false.
```javascript
asscroll.enable({ restore: true })
```
--------------------------------
### asscroll.targetPos
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Returns the target scroll position.
```APIDOC
## asscroll.targetPos
### Description
Returns the target scroll position.
### Returns
- **number** - Target scroll position
```
--------------------------------
### Set current scroll position with asscroll.currentPos
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Sets the scroll position to 200, bypassing any lerps. Use this to directly control the scroll position without smoothing.
```javascript
asscroll.currentPos = 200
```
--------------------------------
### asscroll.on('update') event listener
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Returns the target scroll position and current scroll position during the internal update loop.
```javascript
asscroll.on('update', ({ targetPos, currentPos }) => console.log(targetPos, currentPos))
```
--------------------------------
### asscroll.disable([parameters])
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Disables ASScroll. Optionally disable only manual scrolling while still allowing transforms.
```APIDOC
## asscroll.disable([parameters])
### Description
Disables ASScroll. Optionally disable only manual scrolling while still allowing transforms.
### Method
disable
### Parameters
#### Optional Parameters
- **parameters** (object) - Optional - Configuration object
- **parameters.inputOnly** (boolean) - Optional - Default: false - Only disable the ability to manually scroll (still allow transforms)
### Request Example
```js
asscroll.disable({ inputOnly: true })
```
### Response
No response value is documented.
```
--------------------------------
### .update()
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Updates the smooth scroll instance. This method recalculates the scroll dimensions and positions.
```APIDOC
## Method: .update()
### Description
Updates the smooth scroll instance. This method recalculates the scroll dimensions and positions.
### Example
```js
asscroll.update()
```
```
--------------------------------
### Enable ASScroll with new scroll elements and reset
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Enables ASScroll on the '.page' element and resets the scroll position to 0. The 'newScrollElements' parameter accepts a boolean, NodeList, or HTMLElement, and 'reset' defaults to false.
```javascript
asscroll.enable({ newScrollElements: document.querySelector('.page'), reset: true })
```
--------------------------------
### asscroll.scrollTo(targetPos, [emitEvent])
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Scrolls the page to a specified position. Optionally controls whether external scroll events are emitted during the scroll.
```APIDOC
## asscroll.scrollTo(targetPos, [emitEvent])
### Description
Scroll to a given position on the page.
### Method
N/A (JavaScript method)
### Parameters
- **targetPos** (number) - Required - Target scroll position
- **[emitEvent]** (boolean) - Optional - Whether to emit the external scroll events or not (default: true)
### Request Example
N/A
### Response
N/A
```
--------------------------------
### asscroll.on('scrollEnd') event listener
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Fires when the lerped scroll position has reached the target position.
```javascript
asscroll.on('scrollEnd', scrollPos => console.log(scrollPos))
```
--------------------------------
### asscroll.scrollElements
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Returns the element(s) that ASScroll is scrolling.
```APIDOC
## asscroll.scrollElements
### Description
Returns the element(s) that ASScroll is scrolling.
### Returns
- **Array** - An array of elements ASScroll is scrolling
```
--------------------------------
### asscroll.update()
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Calls the internal animation frame request callback. This method is used to manually trigger the update loop.
```APIDOC
## asscroll.update()
### Description
Calls the internal animation frame request callback.
### Method
update
### Endpoint
asscroll.update()
### Parameters
None
### Request Example
```js
asscroll.update()
```
### Response
No return value.
```
--------------------------------
### .off(eventName, callback)
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Removes an event listener that was previously registered with the `.on()` method.
```APIDOC
## Method: .off(eventName, callback)
### Description
Removes an event listener that was previously registered with the `.on()` method.
### Parameters
- `eventName` (string) - Required - The name of the event to remove the listener from.
- `callback` (function) - Required - The function to remove.
### Example
```js
asscroll.off('scroll', handler)
```
```
--------------------------------
### asscroll.maxScroll
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Returns the maximum scroll height of the page.
```APIDOC
## asscroll.maxScroll
### Description
Returns the maximum scroll height of the page.
### Returns
- **number** - Maxmium scroll height
```
--------------------------------
### asscroll.containerElement
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Returns the outer element that ASScroll is attached to.
```APIDOC
## asscroll.containerElement
### Description
Returns the outer element that ASScroll is attached to.
### Returns
- **HTMLElement** - The outer element
```
--------------------------------
### asscroll.on('scroll') event listener
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Logs out the scroll position when the 'scroll' event is fired.
```javascript
asscroll.on('scroll', scrollPos => console.log(scrollPos))
```
--------------------------------
### Disable ASScroll input only
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Disables the ability to manually scroll while still allowing position updates via asscroll.currentPos. The 'inputOnly' parameter defaults to false.
```javascript
asscroll.disable({ inputOnly: true })
```
--------------------------------
### External window resize with disableResize
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Disables ASScroll's internal resize handling to avoid extra browser calculations. Pass your own width and height values to asscroll.resize() inside your existing resize listener.
```Javascript
const asscroll = new ASScroll({
disableResize: true
})
window.addEventListener('resize', () => {
// trigger other resize logic
const width = window.innerWidth
const height = window.innerHeight
asscroll.resize({ width, height })
})
```
--------------------------------
### asscroll.isHorizontal
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Returns whether or not ASScroll is in horizontal scroll mode.
```APIDOC
## asscroll.isHorizontal
### Description
Returns whether or not ASScroll is in horizontal scroll mode.
### Returns
- **boolean** - The status of horizontal scroll
```
--------------------------------
### Custom Scrollbar HTML Structure
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Default HTML structure added when customScrollbar is enabled. The classes can be changed via scrollbarEl and scrollbarHandleEl options, and styles can be overridden with scrollbarStyles: false.
```HTML
```
--------------------------------
### .disable([parameters])
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Disables the smooth scroll functionality. This method stops the smooth scrolling behavior.
```APIDOC
## Method: .disable([parameters])
### Description
Disables the smooth scroll functionality. This method stops the smooth scrolling behavior.
### Parameters
- `parameters` (Object) - Optional - Configuration options for disabling.
### Example
```js
asscroll.disable()
```
```
--------------------------------
### asscroll.off(eventName, callback)
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Removes an event listener for a specified event. The callback should match the one used when adding the listener.
```APIDOC
## asscroll.off(eventName, callback)
### Description
Removes an event listener for a specified event. The callback should match the one used when adding the listener.
### Method
off
### Endpoint
asscroll.off(eventName, callback)
### Parameters
- **eventName** (string) - Required - Name of the event.
- **callback** (function) - Required - Callback function.
### Request Example
```js
asscroll.off('scroll', scrollHandler)
```
### Response
No return value.
```
--------------------------------
### External requestAnimationFrame with disableRaf
Source: https://github.com/ashthornton/asscroll/blob/master/README.md
Disables ASScroll's internal rAF loop to avoid performance impact from multiple loops. Use a custom RAF loop or GSAP's ticker to call asscroll.update().
```Javascript
const asscroll = new ASScroll({
disableRaf: true
})
// Regular RAF loop
requestAnimationFrame(onRaf)
function onRaf() {
asscroll.update()
requestAnimationFrame(onRaf)
}
// Or use with GSAP's internal RAF
gsap.ticker.add(asscroll.update)
```