All Projects → soenkekluth → Sticky State

soenkekluth / Sticky State

StickyState is a high performant module making native position:sticky statefull and polyfilling the missing sticky browser feature

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Sticky State

Fixed Sticky
DEPRECATED: A position: sticky polyfill that works with filamentgroup/fixed-fixed for a safer position:fixed fallback.
Stars: ✭ 1,490 (+115.32%)
Mutual labels:  polyfill, scrolling, sticky
Scroll Into View If Needed
Element.scrollIntoView ponyfills for things like "if-needed" and "smooth"
Stars: ✭ 811 (+17.2%)
Mutual labels:  polyfill, scrolling
Floatthead
Fixed <thead>. Doesn't need any custom css/html. Does what position:sticky can't
Stars: ✭ 1,193 (+72.4%)
Mutual labels:  scrolling, sticky
react-native-audio-polyfill
Audio polyfill for desktop and native.
Stars: ✭ 13 (-98.12%)
Mutual labels:  polyfill, native
Stickyfill
Polyfill for CSS `position: sticky`
Stars: ✭ 2,252 (+225.43%)
Mutual labels:  polyfill, scrolling
Share Api Polyfill
A polyfill for the sharing that can be used in desktop too, so your users can shere in their twitter, facebook, messenger, linkedin, sms, e-mail, print, telegram or whatsapp.
Stars: ✭ 210 (-69.65%)
Mutual labels:  polyfill, native
react-sticky-headroom
A React Component to hide a Header using CSS sticky position
Stars: ✭ 22 (-96.82%)
Mutual labels:  scrolling, sticky
Sauron Native
Truly cross platform, truly native. multiple backend GUI for rust
Stars: ✭ 587 (-15.17%)
Mutual labels:  native
Little State Machine
📠 React custom hook for persist state management
Stars: ✭ 654 (-5.49%)
Mutual labels:  state
Node Config
Node.js Application Configuration
Stars: ✭ 5,423 (+683.67%)
Mutual labels:  state
Bootstrap Ie7
Bootstrap 3 CSS for IE7
Stars: ✭ 578 (-16.47%)
Mutual labels:  polyfill
Polyfill Service
Automatic polyfill service.
Stars: ✭ 5,585 (+707.08%)
Mutual labels:  polyfill
Jsbi
JSBI is a pure-JavaScript implementation of the official ECMAScript BigInt proposal.
Stars: ✭ 663 (-4.19%)
Mutual labels:  polyfill
Recyclerview Fastscroller
A fully customizable Fast Scroller for the RecyclerView in Android, written in Kotlin
Stars: ✭ 585 (-15.46%)
Mutual labels:  scrolling
Stent
Stent is combining the ideas of redux with the concept of state machines
Stars: ✭ 681 (-1.59%)
Mutual labels:  state
Vue Nodegui
Build performant, native and cross-platform desktop applications with native Vue + powerful CSS like styling.🚀
Stars: ✭ 575 (-16.91%)
Mutual labels:  native
Proton
Purely native and extensible rich text editor for iOS and macOS Catalyst apps
Stars: ✭ 685 (-1.01%)
Mutual labels:  native
Scrolldir
0 dependency JS plugin to leverage scroll direction with CSS ⬆⬇ 🔌💉
Stars: ✭ 679 (-1.88%)
Mutual labels:  scrolling
Gumshoe
A simple vanilla JS scrollspy script.
Stars: ✭ 640 (-7.51%)
Mutual labels:  scrolling
Text Encoding
Polyfill for the Encoding Living Standard's API
Stars: ✭ 629 (-9.1%)
Mutual labels:  polyfill

#StickyState

StickyState adds state to position:sticky elements and also polyfills the missing native sticky feature.

Dependency free, pure Javascript for IE9+.

Today's browsers do not all support the position:sticky feature (which by the way is being used (polyfilled) on pretty much every site you visit) - moreover the native supported feature itself comes without a readable state. Something like a:hover => div:sticky to add different styles to the element in its sticky state - or to read the state if needed in JavaScript.

Unlike almost all polyfills you can find in the wild, StickyState is highly performant. The calculations are reduced to a minimum by persisting several attributes.

In some cases you also need to know in which direction the user scrolls - for example if you want to hide a sticky header when the user scrolls up. if you set the scrollClass property of the options StickyState will add your choosen classNames to the element when it is sticky and scrolling.

As a standalone Library its 6.75kb gzipped.

Warning concerning Chromes implementation of native position:sticky

it looks like chromes implementaton of position:sticky is different to all other implementations out there. don't know if thats a bug - but bottom is currently not recognized by chrome. there will be a fix for this soon in sticky-state

Dependencies

none!

Browser support

IE >= 9, *


Install

npm install sticky-state

Demo

all you can eat

https://rawgit.com/soenkekluth/sticky-state/master/examples/index.html

headroom style

https://rawgit.com/soenkekluth/sticky-state/master/examples/headroom.html

simple

https://rawgit.com/soenkekluth/sticky-state/master/examples/simple.html


css

Your css should contain the following lines: (you can specify the classNames in js) https://github.com/soenkekluth/sticky-state/blob/master/dist/sticky-state.css

.sticky {
  position: -webkit-sticky;
  position: sticky;
}

.sticky.sticky-fixed.is-sticky {
  position: fixed;
  -webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  backface-visibility: hidden;
}

.sticky.sticky-fixed.is-sticky:not([style*="margin-top"]) {
  margin-top: 0 !important;
}
.sticky.sticky-fixed.is-sticky:not([style*="margin-bottom"]) {
  margin-bottom: 0 !important;
}

.sticky.sticky-fixed.is-absolute{
  position: absolute;
}


js

var StickyState = require('sticky-state');
new StickyState(document.querySelectorAll('.sticky'));
//  all elements with class .sticky will have sticky state:

options

var StickyState = require('sticky-state');

// the props you can set (except scrollClass this shows the default options):



var stickyOptions = {
  disabled: false, // disable or enable the sticky feature initially
  className: 'sticky', // the core class which should be equal to the css. see above.
  stateClassName: 'is-sticky',  // the state class, when the element is actually sticky
  fixedClass: 'sticky-fixed',  // the fallback class that uses position:fixed to make the element sticky 
  wrapperClass: 'sticky-wrap', // the fallback (polyfilled) version needs a placeholder that uses the space of the actual sticky element when its position:fixed
  wrapFixedSticky: true,  // by default the sticky element gets wrapped by the placeholder. if you set it to false it will be inserted right before it.
  absoluteClass: 'is-absolute',  // the polyfilled sticky element needs to be position:absolut in some cases.
  
  // scrollclass will add a class to the sticky element that is depending on the scroll direction when the element is sticky.
  // when the scrolling stops the class will be the value of "none" unless you set "persist" to true.
  
  scrollClass: {
    down: null,
    up: null,
    none: null,
    persist: false
  }
};

// instantiate with options
var stickyElements = new StickyState(document.querySelectorAll('.sticky'), stickyOptions);

api / events

var StickyState = require('sticky-state');
new StickyState(document.querySelectorAll('.sticky'))
  .on('sticky:on', function(e){console.log('sticky:on', e.target);})
  .on('sticky:off', function(e){console.log('sticky:off' ,e.target);});


React Component

https://github.com/soenkekluth/react-sticky-state

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].