Giter Site home page Giter Site logo

i-sticky's Introduction

i-sticky

"position: sticky" jQuery plugin / polyfill.

Limitations

  • only vertical direction is supported
  • if native position:sticky support is detected, and no force option is set, the plugin does nothing
  • you shouldn't set left or right CSS properties on sticky positioned element
  • you should set top, bottom or margin-left properties in pixels only
  • parent block of position:sticky element MUST have position different from static (f.e., relative is a good choice)

Usage

jQuery is required (tested with 1.8.3 .. 1.10.2, should work with 1.7.0 or newer). Then write some JS:

$('.i-sticky').iSticky();

You should write CSS rules by yourself, as you normally would. For example:

/* sticky element */
.i-sticky {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    height: 30px;
}
/* don't forget to change positioning of parent element */
.some-sticky-parent {
    position: relative;
}

Methods

Remove sticky style

$('.i-sticky').iSticky('unstick');

Options

  • holderClass: sets up className for the placeholder element, which is created to hold original element's place in flow. Default value is i-sticky__holder.
  • holderAutoHeight: when true, the plugin will recalculate placeholder's height. Otherwise, your CSS should define it. Defaults to true.
  • force: applies the plugin even if the browser has native position:sticky support. May be useful for testing.
  • debug: writes some info to browser's console.
  • fixWidth: copies parent's width. Enabled by default.
  • stuckClass: class added when stuck.

Example with options:

$('.i-sticky').iSticky({
    holderClass:      'i-sticky__holder',
    holderAutoHeight: false
});
/* if holderAutoHeight is off, don't forget to set some styles
   for the placeholder, generated by plugin */
.i-sticky + .i-sticky__holder {
    height: 30px;
}

TODO

  • Position:sticky should not work if one of ancestors has overflow (auto/scroll/hidden) or overflow-x/overflow-y styles (Safari's behavior).
  • Position:sticky should work as position:relative on table element.
  • Sticky thead/tfoot.
  • Plugin should set position:relative to sticky's parent.
  • Margin-top & margin-bottom support.
  • Crossbrowser testing, including native support tests and comparison with the plugin's behavior.

Migration from 2.2.5 and below

Remove position:relative rule from all your sticky elements (position only with -webkit-stiky and sticky). Then recheck everything and adjust wrapper styles when needed.

License

MIT

  • Copyright (c) 2014 Sergey Ermakov
  • Copyright (c) 2016 REG.RU LLC

Contributors

Examples in the wild

REG.COM domain checker

Changelog

  • 2017-09-09 3.0.2 cleanup
  • 2017-09-09 3.0.1 package.json
  • 2017-02-10 2.2.6 force unsupported state for chrome 56. By @shifteee
  • 2016-11-12 3.0.0 position:static in home state (was position:relative). fixWidth is enabled by default.
  • 2016-11-12 2.2.5 fix: fixWidth option is back.
  • 2016-11-12 2.2.4 fixes.
  • 2016-11-08 2.2.3 bugfix. By @DesTincT.
  • 2016-11-08 2.2.2 transfering project to github/regru.
  • 2016-11-07 2.2.1 fixes. By @DesTincT.
  • 2016-11-07 2.2.0 stuckClass option. By @DesTincT.
  • 2016-03-26 2.1.0 fixWidth option.
  • 2015-12-14 2.0.0 Rewritten to support both top & bottom at the same time. New force and debug options. holderAutoHeight defaults to true.
  • 2015-06-15 1.1.8 Min-width issue. By @anagami.
  • 2015-06-08 1.1.7 Test html pages. Positioning issue. By @anagami.
  • 2015-06-04 1.1.6 Positioning issue. By @anagami.
  • 2015-06-04 1.1.5 Holder is hidden when block is not sticked. Position issue. By @anagami.
  • 2015-03-30 1.1.4 Firefox issue. By @anagami.
  • 2015-03-30 1.1.3 Unstick issue. By @anagami.
  • 2015-03-27 1.1.2 Small refactoring. By @anagami.
  • 2015-03-27 1.1.1 Holder is removed when unstick. By @anagami.
  • 2015-03-27 1.1.0 New 'unstick' method. By @anagami.
  • 2014-10-08 1.0.0 Initial release.

i-sticky's People

Contributors

podkot avatar shifteee 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.