0.1.2 • Published 4 years ago

actonscroll v0.1.2

Weekly downloads
6
License
Apache-2.0
Repository
github
Last release
4 years ago

Tool to perform an action when a user scrolls in a web page.

Installation

$ yarn add actonscroll

Usage

import Actonscroll from 'actonscroll';

// Passing arguments to the creator
(new Actonscroll({ action: () => console.log('Scrooolling!') }))
  .start();

// Calling specific method for each option
(new Actonscroll())
  .action(() => console.log('Scrooolling!'))
  .start();

// Stop
const actonscroll = new Actonscroll();
actonscroll.start();
actonscroll.stop();

Documentation

Actonscroll

Executes a predefined action when the scroll event is triggered.

Kind: global class

new Actonscroll(options)

ParamType
optionsObject
options.containerDocument / Element
options.actionfunction
options.conditionsObject
options.throttlingnumber
options.onceboolean

actonscroll.container(container) ⇒ Actonscroll

Sets the container element within which the scroll will be listened.

Kind: instance method of Actonscroll

ParamType
containerElement

Example

actonscroll.container(document.querySelector('.my-container'));

actonscroll.action(action) ⇒ Actonscroll

Sets an action to be performed when the scroll event is triggered.

Kind: instance method of Actonscroll

ParamType
actionfunction

Example

actonscroll.action(() => console.log('Scrooolling!'));

actonscroll.conditions(conditions) ⇒ Actonscroll

Sets a list of conditions to determine whether the configured action has to be performed or not.

Kind: instance method of Actonscroll

ParamTypeDescription
conditionsObject
conditions.directionsArray.<string>Allowed values: 'all', 'vertical', 'horizontal', 'up', 'down', 'left', 'right'.
conditions.offsetObject{ x, y } (In pixels).
conditions.customfunction

Example

actonscroll.conditions({
  directions: ['up', 'left'],
  offset: { y: 200 },
  custom: () => true,
});

actonscroll.throttling(throttling) ⇒ Actonscroll

Sets a throttling time (ms) to the scroll event.

Kind: instance method of Actonscroll

ParamType
throttlingnumber

Example

actonscroll.throttling(1000);

actonscroll.once(once) ⇒ Actonscroll

Determines whether the action should be performed once or not.

Kind: instance method of Actonscroll

ParamTypeDefault
oncebooleantrue

Example

actonscroll.once();

actonscroll.start()

Executes the configured action after checking that all the conditions are satisfied.

Kind: instance method of Actonscroll Example

actonscroll.start();

actonscroll.stop()

Removes the actonscroll from the configured container.

Kind: instance method of Actonscroll Example

actonscroll.stop();