Skip to content

Repository files navigation

Cuberto Reeller

NPM VersionLicenceBundle file sizeBundle file size (gzip)NPM DownloadsGitHub Workflow Status

Flexible, powerful and modern library for creating the running horizontal blocks effect, also known as ticker or the «marquee effect».

The library uses GSAP, IntersectionObserver and ResizeObserver to achieve the best performance results.

Dependencies

GSAP v3 (https://greensock.com/gsap/)

Quick start

Install from NPM

Reeller requires GSAP library to work.

npm install gsap --save
npm install reeller --save

Import GSAP, Reeller and initialize it:

importReellerfrom'reeller';importgsapfrom'gsap';Reeller.registerGSAP(gsap);constreeller=newReeller({container: '.my-reel',wrapper: '.my-reel-wrap',itemSelector: '.my-reel-item',speed: 10,});

Use from CDN

If you don't want to include Reeller files in your project, you can use library from CDN:

<scriptsrc="https://unpkg.com/reeller@0/dist/reeller.min.js"></script>

Reeller requires GSAP to work. You need to import it above the Reeller if you didn't have it before:

<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/gsap.min.js"></script><scriptsrc="https://unpkg.com/reeller@0/dist/reeller.min.js"></script><script>varreeller=newReeller.Reeller({container: '.my-reel',wrapper: '.my-reel-wrap',itemSelector: '.my-reel-item',speed: 10,});</script>

Note: All modules (Reeller, Filler, ScrollerPlugin, DragPlugin) will be imported into Reeller namespace when using from CDN, so you must use a prefix.

Options

You can configure Reeller via options.

The following options with defaults is available:

constreeller=newReeller({container: null,wrapper: null,itemSelector: null,cloneClassName: '-clone',speed: 10,ease: 'none',initialSeek: 10,loop: true,paused: true,reversed: false,autoStop: true,autoUpdate: true,clonesOverflow: true,clonesFinish: false,clonesMin: 0,});
OptionTypeDefaultDescription
containerstring | HTMLElementnullRequired. Container element or selector.
wrapperstring | HTMLElementnullRequired. Inner element or selector.
itemSelectorstringnullRequired. Items CSS selector.
cloneClassNamestring-cloneClass name of the new clones.
speednumber10Movement speed.
easestring'none'Timing function. See gsap easing.
initialSeeknumber10Initial seek of timeline.
loopbooleantrueLoop movement.
pausedbooleantrueInitialize in paused mode.
reversedbooleanfalseReverse mode.
autoPlaybooleantrueUse IntersectionObserver to auto play/stop movement.
autoUpdatebooleantrueUse ResizeObserver to auto update clones number.
clonesOverflowbooleantrueCreate artificial overflow with clones.
clonesFinishbooleanfalseBring the cycle of clones to an end.
clonesMinboolean0Minimum number of clones.
pluginsObjectnullOptions for plugins. See Plugins section.

API

Methods

MethodDescription
reeller.resume()Resumes movement.
reeller.pause()Pauses movement.
reeller.reverse([reversed=true])Set reversed moving.
reeller.invalidate()Refresh GSAP Timeline.
reeller.update()Calculates and sets the number of clones and update movement position.
reeller.refresh(update=true)Fully refresh and update all clones and position. Use this only after adding or removing original items.
reeller.destroy(removeClones=true)Destroy Reeller instance, detach all observers and remove clones.
Reeller.registerGSAP(gsap)Static method to register the gsap library.
Reeller.use(...plugins)Static method to register a plugins.

Properties

PropertyTypeDescription
reeller.pausedbooleanIndicates that the movement is stopped.
reeller.tlTimelineGSAP Timeline.
reeller.fillerFillerInner Filler instance. See Filler section.
reeller.optionsReellerOptionsCurrent Reeller options.
reeller.pluginObjectInitialized plugins.

Events

Reeller comes with a useful events you can listen. Events can be assigned in this way:

reeller.on('update',()=>{console.log('Reeller update happened!');});

You can also delete an event that you no longer want to listen in these ways:

reeller.off('update');reeller.off('update',myHandler);
EventArgumentsDescription
update(reeller, calcData)Event will be fired after update.
refresh(reeller)Event will be fired after refresh.
destroy(reeller)Event will be fired after destroy.

Plugins

Reeller support plugins to extend functionality.

At this moment there are two plugins that come with the official package: ScrollerPlugin and DragPlugin.

ScrollerPlugin

This plugin allows you to attach movement to the scroll:

import{Reeller,ScrollerPlugin}from'reeller';importgsapfrom'gsap';Reeller.registerGSAP(gsap);Reeller.use(ScrollerPlugin);constreeller=newReeller({container: '.my-reel',wrapper: '.my-reel-wrap',itemSelector: '.my-reel-item',speed: 10,plugins: {scroller: {speed: 1,multiplier: 0.5,threshold: 1,},},});

The following options of ScrollerPlugin is available:

OptionTypeDefaultDescription
speednumber1Movement and inertia speed.
multipliernumber0.5Movement multiplier.
thresholdnumber1Movement threshold.
easestring'expo.out'Timing function. See gsap easing.
overwritebooleantrueSee gsap overwrite modes.
bothDirectionbooleantrueAllow movement in both directions.
reversedbooleanfalseReverse scroll movement.
stopOnEndbooleanfalseStop movement on end scrolling.
scrollProxyfunctionnullA function that returns the scroll position. Can be used in cases with custom scroll.

In cases with using of custom scroll libraries (e.g. smooth-scrollbar), you can use the scrollProxy option to return the current scroll position:

importScrollbarfrom'smooth-scrollbar';import{Reeller,ScrollerPlugin}from'reeller';importgsapfrom'gsap';Reeller.registerGSAP(gsap);Reeller.use(ScrollerPlugin);constscrollbar=Scrollbar.init(document.querySelector('#my-scrollbar'));constreeller=newReeller({container: '.my-reel',wrapper: '.my-reel-wrap',itemSelector: '.my-reel-item',speed: 10,plugins: {scroller: {speed: 1,multiplier: 0.5,threshold: 1,scrollProxy: ()=>scrollbar.scrollTop,},},});

DragPlugin

DragPlugin adds horizontal drag control with inertia:

import{Reeller,DragPlugin}from'reeller';importgsapfrom'gsap';Reeller.registerGSAP(gsap);Reeller.use(DragPlugin);constreeller=newReeller({container: '.my-reel',wrapper: '.my-reel-wrap',itemSelector: '.my-reel-item',speed: 10,plugins: {drag: {speed: 1,multiplier: 1,axis: 'y',invertAxis: true,changeDirection: true,inertiaMultiplier: 0.2,},},});

The following options of DragPlugin is available:

OptionTypeDefaultDescription
speednumber1Inertia duration in seconds.
multipliernumber1Drag movement multiplier.
thresholdnumber50Minimum release velocity in px/s required to start inertia.
inertiaMultipliernumber0.2Inertia distance multiplier.
activationDistancenumber3Minimum pointer movement in px before drag starts.
maxVelocitynumber3000Maximum release velocity in px/s used for inertia calculation.
easestring'expo.out'Timing function. See gsap easing.
changeDirectionbooleanfalseChange autoplay direction to match the last drag direction after release.
axis'x' | 'y''x'Pointer axis used for drag. Set 'y' when the reel is rotated by -90deg.
invertAxisbooleanfalseInvert drag direction on the selected axis. Useful with rotated reels.
targetstring | HTMLElement | nullnullDrag target element or selector. Defaults to the Reeller container.
preventDefaultbooleantruePrevent default pointer behaviour while dragging.

Filler

Reeller library works on top of the Filler module. This is a separate tool for automatically calculating the number of clones and filling the container with them.

You can use only Filler (without Reeller) if you need to fill the whole space with clones, without movement, animations and GSAP:

import{Filler}from'reeller';constfiller=newFiller({container: '.my-container',itemSelector: '.-my-item',cloneClassName: '-clone',});

Options

OptionTypeDefaultDescription
containerstring | HTMLElementnullRequired. Container element or selector.
itemSelectorstringnullRequired. Items CSS selector.
wrapperstring | HTMLElementnullInner element or selector.
cloneClassNamestring'-clone'Class name of the new clones.
autoUpdatebooleantrueUse ResizeObserver to auto update clones number.
clonesOverflowbooleanfalseCreate artificial overflow with clones.
clonesFinishbooleanfalseBring the cycle of clones to an end.
clonesMinbooleanfalseMinimum number of clones.

Methods

MethodDescription
filler.addClones(count, offset=0)Creates and adds clones to end in the desired number from given offset.
filler.removeClones(count)Removes the desired number of clones from the end.
filler.setClonesCount(count)Sets the desired number of clones.
filler.getCalcData()Returns a calculated data object (number of clones, widths, etc.)
filler.update()Calculates and sets the number of clones.
filler.refresh(update=true)Fully refresh and update all clones. Use this only after adding or removing original items.
filler.destroy(removeClones=true)Destroy Filler instance, detach all observers and remove clones.

Properties

PropertyTypeDescription
filler.containerHTMLElementContainer element.
filler.wrapperHTMLElementInner element.
filler.itemArray.<HTMLElement>Items array.
filler.calcDataObjectCalculated data (number of clones, widths, etc.).
filler.optionsReellerOptionsCurrent Filler options.

Events

EventArgumentsDescription
update(filler, calcData)Event will be fired after update.
refresh(filler)Event will be fired after refresh.
destroy(filler)Event will be fired after destroy.

Examples of use

License

The MIT License (MIT)

About

Flexible, powerful and modern library for creating the running horizontal blocks effect, also known as ticker or the «marquee effect».

Resources

Stars

96 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages