A small jQuery plugin for rendering scroll-based HTML animations

Overview

Storyline

Build beautiful landing pages that change as the user scrolls up or down.

Project created in 2013 and ported to GitHub in 2021.

Demo

Just visit this page for a short demo of the plugin and included console/debugger.

Getting started

Include the Storyline library

<script defer src="https://markjivko.com/storyline/js/storyline.min.js"></script>

Define your frames

$(document).ready(function(){
    $.storyline({
        frames: {
            'frameSelector': {
                onEnter: function(c,e){},
                onActive: function(c,e){},
                onLeave: function(c,e){},
                scrollIntoView: false
            }
        },
        // @see Options
    });
})
  • 'frameSelector' - String; a selector for the target storyline frame.
  • onEnter - Function; called when the frame becomes visible.
  • onActive - Function; called while the frame is visible, on each scroll event.
  • onLeave - Function; called when the frame becomes invisible to the user.
  • scrollIntoView - Boolean; overrides the option with the same name; triggered 250ms after onEnter to perform a scrollIntoView action

You can add as many frame selectors as you wish. Each selector can point to either 1 HTML element (for instance, an #id selector) or to many HTML elements (a .class selector etc.).

Action parameters

Each action defined for the frame selectors (onEnter, onActive, onLeave) gets 2 extra parameters on each call.

  • c - Object; frame coordinates:
{
    frameTop: 66, // Integer - distance from the frame to the top of the page (@see Options - frameTop)
    frameLeft: 8, // Integer - distance from the frame to the left side of the page
    frameBottom: 240, // Integer - distance from the frame to the bottom of the page
    frameRight: 8, // Integer - distance from the frame to the left side of the page
    frameWidth: 1247, // Integer - frame width in pixels
    frameHeight: 400, // Integer - frame height in pixels
    screenWidth: 1263, // Integer - screen width in pixels
    screenHeight: 706, // Integer - screen height in pixels
    screenScrollTop: 342, // Integer - how much the page was scrolled
    frameMiddleDistance: -77, // Integer - distance from the frame middle to the center of the screen
    percent: {
       screenPlayed=20.00, // Float - How much the page was scrolled; percent
       frameVisible=100.00, // Float - How much of the frame is visible; percent
       frameUnCentered=-21.81 // Float - How much is the frame off center; percent, -100 to +100
    }
}
  • e - Object; scroll event.

You can use both of these objects to fully control the behavior of frame elements such as positions, colors, backgrounds etc. in a predictible, linear fashion.

Frame reference

Each action also gets a reference of the selector via the $(this) operator. Furthermore, the frame itself has an object atached:

$(this).data("frameInfo")
// Returns
{
    framePosition: 2, // Integer - frame index (1 to number of frames)
    frameSelector: '.frame2', // String - frame selector
    frameName: 'contact' // String - frame name (@see Options - buildMenu)
}

Options

You can further customize your storyline with the following options:

// Available options and their defaults
{
    frameTop: 0, // Distance from the focused frame to the window top
    guide: false, // Boolean - Show the storyline guide 
    buildMenu: false, // Boolean|Array - List of names for each frame
    menuSpeed: 1500, // Integer - Scroll duration for menu clicks
    tolerance: 20, // Integer - frame tolerance
    logLevel: 'debug', // String - log level,
    scrollIntoView: false, // Boolean - Default value for scroll into view
    ignoreWarnings: true // Boolean - If set to false, the storyline will fail on each error
}

Options - frameTop

This is used to set the distance from the focused frame to the top of the screen; useful for when a floating menu bar is fixed at the top of the screen.

Options - guide

Wether to show or hide the Storyline guide. If set to true, you will get a visual representation of each frame, its parameters, position, state etc. You will also get the Storyline Log showing you information such as debugging data, script information, errors etc.

Options - buildMenu

If you set this option to a valid array of strings, each one will be interpreted as the name of a frame, in the order passed to the frames key above. Plus, a menu will be constructed with the provided list of frame names; each time a user clicks on a menu item, the page will scroll to the correspondent frame.

Options - menuSpeed

If a menu was constructed an an user clicks on a menu item, this option sets the interval (in milliseconds) in which the page will scroll to the correspondent frame.

Options - tolerance

This is used to trigger the onEnter and onLeave actions more loosely. Test using the guide option set to true.

Options - scrollIntoView

This is triggered 250ms after onEnter and performs a scrollIntoView action. The homonymous parameter in frames overrides this global option.

Options - ignoreWarnings

If another option is set incorrectly and ignoreWarnings is set to True, the script will halt at the first encountered error.

Architecture

The plugin is very well commented. All strings are stored in a message variable.

{
    error:{}, // Error messages
    status:{}, // Status messages
    const:{} // Constants
}

The plugin also uses an error logging mechanism with log level filtering.

// Available log levels
logLevel = {
    debug:'debug',
    info:'info',
    error:'error'
}
// How to use
log(message.status.x, logLevel.debug); // Log a debugging message at index "x"
log(message.status.y, logLevel.info); // Log an information message at index "y"
log(message.error.z, logLevel.error); // Log an error message at index "z"

You can also set the log level by changing the logLevel option.

You can view the log either in the browser console or in the Storyline Log when the guide option is set to true.

Examples of sites using the Storyline plugin

You might also like...

A small library for creating typing animations.

A small library for creating typing animations. View a short video demonstration here. Installation npm i tiper-js Usage Initialization is really simp

Nov 5, 2022

Small example showing how you can make game sprite animations using CSS with Javascript movement.

Small example showing how you can make game sprite animations using CSS with Javascript movement.

Hi there, I'm Björn Hjorth 👋 I like combining the web and game development, if you like what you see please do not be a stranger and say "Hi" on Twit

Nov 9, 2022

A jQuery plugin that works in harmony with animate.css in order to enable animations only when content comes into view.

jQuery AniView A jQuery plugin that works in harmony with animate.css in order to enable animations only when content comes into view. Now supports v4

Sep 10, 2022

A fullscreen scroll-based slideshow with a content view powered by GreenSock's Observer plugin.

A fullscreen scroll-based slideshow with a content view powered by GreenSock's Observer plugin.

Fullscreen Scrolling Slideshow A fullscreen scroll-based slideshow with a content view powered by GreenSock's Observer plugin. Article on Codrops Demo

Jan 3, 2023

Gofiber with NextJS Static HTML is a small Go program to showcase for bundling a static HTML export of a Next.js app

Gofiber and NextJS Static HTML Gofiber with NextJS Static HTML is a small Go program to showcase for bundling a static HTML export of a Next.js app. R

Jan 22, 2022

Javascript library for switching fixed elements on scroll through sections. Like Midnight.js, but without jQuery

Library for Switching Fixed Elements on Scroll Sometimes designers create complex logic and fix parts of the interface. Also they colour page sections

Sep 19, 2022

A custom Chakra UI component that adds ready-made styles for rendering remote HTML content.

Chakra UI Prose Prose is a Chakra UI component that adds a ready-made typography styles when rendering remote HTML. Installation yarn add @nikolovlaza

Jan 3, 2023

Tempo is an easy, intuitive JavaScript rendering engine that enables you to craft data templates in pure HTML.

Tempo 2.0 Tempo is an easy, intuitive JavaScript rendering engine that enables you to craft data templates in pure HTML. Why use Tempo? Clear separati

Jan 3, 2023

A small, lightweight JavaScript plugin for placing items in straight rows (jQuery and vanilla JS version) – Demo:

A small, lightweight JavaScript plugin for placing items in straight rows (jQuery and vanilla JS version) – Demo:

rowGrid.js rowGrid.js is a small, lightweight (~1000 bytes gzipped) jQuery plugin for placing images (or other items) in straight rows. The grid is si

Jul 22, 2022
Owner
Mark Jivko
CTO | Software Architect
Mark Jivko
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
✏️ A small jQuery extension to turn a static HTML table into an editable one. For quickly populating a small table with JSON data, letting the user modify it with validation, and then getting JSON data back out.

jquery-editable-table A small jQuery extension to turn an HTML table editable for fast data entry and validation Demo ?? https://jsfiddle.net/torrobin

Tor 7 Jul 31, 2022
A small javascript DOM manipulation library based on Jquery's syntax. Acts as a small utility library with the most common functions.

Quantdom JS Quantdom is a very small (about 600 bytes when ran through terser & gzipped) dom danipulation library that uuses a Jquery like syntax and

Sean McQuaid 7 Aug 16, 2022
Lightweight and easy to use vanilla js library to add css animations to elements on scroll.

Scrollrisen Trigger css animations on scroll as elements enter the viewport. Zero dependencies, lightweight and easy to use and customize Installation

null 1 Oct 13, 2022
Chakra UI Animations is a dependancy which offers you pre-built animations for your Chakra UI components.

Chakra UI Animations Chakra UI Animations is a dependancy which offers you pre-built animations for your Chakra UI components. Installation yarn add @

Code Chemistry Inc. 9 Nov 19, 2022
A simple jQuery extension to make any HTML element sticky on scroll.

jquery.sticky.js A simple jQuery extension to make any HTML element sticky on scroll. Installation Just download the script and include it in your HTM

Achal Jain 2 Aug 22, 2022
A Simple jQuery Plugin for Animating Scroll

AnimateScroll A Simple jQuery Plugin for Animating the Scroll Demo can be seen at http://plugins.compzets.com/animatescroll What is it exactly? Animat

Ram 714 Jul 21, 2022
infiniteScrollWithTemplate - JQuery plugin for ajax-enabled infinite page scroll / auto paging with template

jQuery Infinite With Template Plugin JQuery plugin for ajax-enabled infinite page scroll with template. If you like jQuery until now, this little libr

이삼구 2 Mar 19, 2021
A jQuery plugin allowing you to scroll an image within a container element

jQuery Scroll Image Inside v0.1 A jQuery plugin allowing you to scroll an image within a container element Usage <div id="window"> <img src="reall

Derek Ashauer 1 Apr 11, 2021