GithubHelp home page GithubHelp logo

jrsouth / stickystack Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 0.0 77 KB

Vanilla Javascript implementation allowing multiple sticky elements, with options for "semi" stickyness, and mobile skipping.

License: MIT License

HTML 37.73% JavaScript 61.15% Shell 1.11%

stickystack's Introduction

stickystack

Vanilla Javascript implementation allowing multiple sticky elements, accounting for horizontal offsets and with options for "semi" stickyness, and mobile skipping.

Installation

Just include stickystack.js in your page's javascript, and add appropriate classes to the HTML elements you want to be sticky. (The script registers a handler which fires on page load to initialise the elements, and on resize to recalculate if necessary.)

Usage

Apply appropriate styles to the elements you want to be involved with the stickyness:

  • js-stickystack -- Elements that should become sticky instead of scrolling offscreen

  • js-stickystack-top -- The element whose top edge should be considered the point at which stickyness begins. This allows external toolbars and other elements that may have other stickyness to remain visible. (Can be applied to an element without the js-stickystack class.)

Modifiers

Elements with the js-stickystackcan be further modified by adding the classes below.

  • js-stickystack-semi -- Elements that will stick until pushed offscreen by another sticky element

  • js-stickystack-nomobile -- Elements that will not be sticky on smaller screens. (Currently hard-coded to <= 768px.)

How it works

More detail coming soon, but basically it gathers a list of sticky HTML elements based on class, creates a set of placeholders that get actived when the respective element is taken out of the layout flow by assigning position: fixed;, and assigns CSS top and z-index values based on page scroll and the stickystack heirarchy.

"Stuck" elements get class stickystack-stuck added to them (and removed when they become unstuck) making it simple to apply theming changes when an element becomes stuck.

stickystack's People

Contributors

jrsouth avatar

Stargazers

Ming Fang avatar Anton Taran avatar Eugene Dvornikov avatar Michael Glenn avatar Rob Neu avatar Neuropass avatar

Watchers

James Cloos avatar  avatar Shireeh Kumar G avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.