Class ScrollTrigger

ScrollTrigger allows you to run actions when the user scrolls a target element (or the main scrollable element) in a given direction, and undo those actions when they scroll in the opposite direction.


To use with auto-widgets (HTML API), see registerTrigger for the specification.

  • Arguments (optional): One or more (comma-separated) scroll directions. Note that if you do not specify any directions, then the trigger will just run once, on any scroll.
  • Additional trigger options:

Show the element when the user scrolls the page up, hide when scrolling down. User scrolling left or right not trigger the action. See getOppositeXYDirections:

<div data-lisn-on-scroll="up @show"></div>

As above, but using a CSS class instead of data attribute:

<div class="lisn-on-scroll--up@show"></div>

Show the element 1000ms after the first time the user scrolls the page up:

<div data-lisn-on-scroll="up @show +once +delay=1000"></div>

Add class scrolled the first time the user scrolls the page in any direction (note that the once option is implied here), and show the element 1000ms after each time the user scrolls the page up, hide it as soon as they scroll down:

<div data-lisn-on-scroll="@add-class=scrolled ;
up @show +do-delay=1000"
></div>

When the user scrolls up or down the closest ancestor with class section, then add classes c1 and c2 and enable trigger my-trigger defined on this same element; undo all of that when scrolling right or left:

<div class="section">
<div data-lisn-on-scroll="up,down @add-class=c1,c2 @enable=my-trigger +scrollable=this.section"
data-lisn-on-run="@show +id=my-trigger"
></div>
</div>

As above, but using data-lisn-ref attribute instead of class selector.

<div data-lisn-ref="section">
<div data-lisn-on-scroll="up,down @add-class=c1,c2 @enable=my-trigger +scrollable=this-section"
data-lisn-on-run="@show +id=my-trigger"
></div>
</div>

Hierarchy (View Summary)

Methods

Constructors

Properties

destroy: () => Promise<void>

Undoes all modifications to the element and returns it to its original state.

You will need to recreate it if you want to enable its functionality again.

disable: () => Promise<void>

Disables the functionality of the widget. What this means is specific to each widget.

enable: () => Promise<void>

Re-enables the functionality of the widget. What this means is specific to each widget.

getActions: () => Action[]

Returns the trigger's actions.

getConfig: () => ScrollTriggerConfig

Returns the trigger config.

getElement: () => Element

Returns the element passed to the widget constructor.

isDestroyed: () => boolean

Returns true if the widget is destroyed.

isDisabled: () => boolean

Returns true if the widget is currently disabled.

onDestroy: (handler: WidgetHandler) => void

The given handler will be called when the widget is destroyed.

onDisable: (handler: WidgetHandler) => void

The given handler will be called when the widget is disabled.

onEnable: (handler: WidgetHandler) => void

The given handler will be called when the widget is enabled.

reverse: () => Promise<void>

"Undo"es all the Actions linked to the trigger.

run: () => Promise<void>

"Do"es all the Actions linked to the trigger.

toggle: () => Promise<void>

"Toggle"s all the Actions linked to the trigger.

toggleEnable: () => Promise<void>

Re-enables the widget if disabled, otherwise disables it.