Git Product home page Git Product logo

sticky-position's Introduction

Deprecated

I feel like browser support for position:sticky is now good enough that I no longer plan to polyfill the feature my projects. Feel free to use this, just know that I don't plan on reaching full compatibility with position:sticky.

Summary

A position: sticky polyfill that's dependency-free and does not modify the DOM tree, i.e., React-friendly. See react-sticky-position for the React component.

Demo

Todo

Install via NPM
npm install sticky-position

Released under the MIT License

sticky-position's People

Contributors

jackmoore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sticky-position's Issues

How is sticky-position finding out native support?

const nativeSupport = (function(){      
        if (this.isSupported !== null) {
            return this.isSupported;
        } else {
            const style = document.createElement('test').style;
            style.cssText = ['-webkit-', '-ms-', ''].map(prefix => `position: ${prefix}sticky`).join(';');
            this.isSupported = style.position.indexOf('sticky') !== -1;
            return this.isSupported;
        }
    }).bind({isSupported: null});

Wouldn't isSupported always be null, so wouldn't the else clause always be executed?

@jackmoore

Doesn't stop when it reaches end of container

Hey @jackmoore thanks for the great little pollyfill!

I have a slight problem with it - I am using a long container to stick a block of content to the page as you scroll down. Firefox's position: sticky will move down until the inner element (primary per your vernacular) hits the bottom of the wrapper, and then stops. In your implementation, the content keeps on going.

To illustrate, I've knocked up a quick jsbin, which you can visit here: http://jsbin.com/ruwokecofu/edit?html,css,js.

Here is how firefox (native position: sticky) handles that:
firefox video showing position sticky hitting bottom of container

And here is chrome (your implementation):
chrome video showing the bug with sticky-position


Your code uses position: fixed which I think is most of the problem. I think a correct implementation here would use position: absolute and have to adjust the top on every scroll - until it reached the bottom of the container.

If you'd like @jackmoore - I can spend a bit of time working on a fix and PR it. If you're happy that I go forward with the suggestion outlined above.

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.