New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

trekk

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trekk

Trekk is a helper library to create timeline and triggered animations based on scroll positions of elements / document.

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

:triangular_flag_on_post: trekk npm version Coverage Status

About

Trekk is a library for making scroll based animations easy-peasy. Trekk does NOT give you anything else than values between 0 and 1 to use in your animation states. The animations you create yourself, or use a library like anime.js.

Install

<script src="https://unpkg.com/trekk@0.1.0/build/trekk.js"></script>
$ npm install trekk

Usage

commonJS

var trekk = require('trekk');

// Define your trails...

trekk() // Start

ES6

import trekk, { trail } from 'trekk';

// Define your trails...

trekk() // Start

API

trekk(options)

Start trekk. You need to run this only once in your scripts.

Options

OptionTypeDefaultDescription
debugbooleanfalseEnter debug mode.
iteratefunction(next)requestAnimationFrameUpdate function.

trail(...)

Use trail to create timelines in your document. All parameters are optional.

Parameters

ParamTypeDefaultDescription
elementnodeundefinedPass a DOM element to use as start and end position of the trail.
startPixelsintegerundefinedStart position of the trail in pixels. If this is a nested trail this will be appended to the parent trail start position.
endPixelsintegerundefinedEnd position of the trail in pixels. If this is a nested trail this will be appended to the parent trail end position.
startPercentagestringundefinedStart position of the trail in percentage. If this is a nested trail it will be a percentage of the parent trail length.
endPercentagestringundefinedEnd position of the trail in percentage. If this is a nested trail it will be a percentage of the parent trail length.
progressfunction(progress)undefinedCalled on update with the current progress.
optionsobject{}Object with options. See below

Options

ParamTypeDefaultDescription
labelstringundefinedUsed as a label when debugging.
offsetfunction(progress)undefinedCalled on update with the current progress.
lerpnumber1Smooth the progress over time with some linear interpolation. Takes a value from 0 to 1.
easestring"linear"Easing function to run before progress is broadcasted. See Easings for supported strings.
waitingfunctionundefinedCalled once when the y scroll position is above the trail start position.
walkingfunctionundefinedCalled once when the y scroll position is within the trail start and end position.
finishedfunctionundefinedCalled once when the y scroll position is below the trail end position.

Examples

Basic

const header = document.querySelector('header')

const fadeInHeader = progress => {
	header.style.opacity = progress
}

const headerTrail = trail(header, fadeInHeader)

Nested

const header = document.querySelector('header')
const title = document.querySelector('.title')
const icon = document.querySelector('.icon')

const fadeInHeader = progress => {
	header.style.opacity = progress
}

const slideInTitle = progress => {
	title.style.transform = `translateX(${100 * progress})`
}

const rotateIcon = progress => {
	icon.style.transform = `rotate(${360 * progress}deg)`
}

const headerTrail = trail(header, fadeInHeader)
headerTrail(100, 200, slideInTitle)
headerTrail('40%', '40%', rotateIcon)

addTimeline(options)

ParamTypeDefaultDescription
optionsobject{}See Options

Options

ParamTypeDefaultDescription
labelstring"Undefined"Used as a label when debugging.
sourcefunction() => window.pageYOffsetFunction that returns source value.
startfunction() => 0Function that returns start position of timeline.
endfunction0Function that returns end position of timeline.
modifierfunction(p, s, e) => (p - s) / (e - s)Function given a source value, calculates the progress in between the start and end value.
lerpnumber1Smooth the progress over time with some linear interpolation. Takes a value from 0 to 1.
easestring, function(progress)"linear"Easing function to run before progress is broadcasted. See Easings for supported strings, or pass your own easing function.
waitingCalled once when the y scroll position is above the trail start position.
walkingCalled once when the y scroll position is within the trail start and end position.
finishedCalled once when the y scroll position is below the trail end position.
progressCalled every progress update with the current progress.

Easings

// linear
// easeInQuad
// easeOutQuad
// easeInOutQuad
// easeInCubic
// easeOutCubic
// easeInOutCubic
// easeInQuart
// easeOutQuart
// easeInOutQuart
// easeInQuint
// easeOutQuint
// easeInOutQuint

Taken from https://gist.github.com/gre/1650294

FAQs

Package last updated on 03 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts