Skip to content

Instantly share code, notes, and snippets.

@jmshal
Last active May 15, 2018 01:54
Show Gist options
  • Save jmshal/4c7dd81a61adcb648944a16b0fac717f to your computer and use it in GitHub Desktop.
Save jmshal/4c7dd81a61adcb648944a16b0fac717f to your computer and use it in GitHub Desktop.

Revisions

  1. jmshal revised this gist Jan 3, 2017. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -46,6 +46,15 @@ require('electron-sticky-shim');

    The shim does not automatically add `position: sticky` to your sticky elements, this is so when Electron does support it natively, you can simply remove the shim and the shim class, and your CSS should work as intended.

    ```html
    <div class="container">
    <div class="sticky-shim" style="position: sticky; top: 0">
    Example
    </div>
    Lorem ipsum...
    </div>
    ```

    ## License

    WTFPL - http://www.wtfpl.net/txt/copying
  2. jmshal revised this gist Jan 3, 2017. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,14 @@

    This 8 line shim makes elements with `position: sticky` work as intended in situations where you have scrollable content nested within your app - see [this](https://twitter.com/heyimjacooob/status/816124902453350400) for an example.

    ## Installation

    You can either copy the `sticky-shim.js` file from this gist, or install it as a module using npm...

    ```sh
    $ npm install --save gist:4c7dd81a61adcb648944a16b0fac717f
    ```

    ## How do I use it?

    You will need to enable the `position: sticky` flag/blink feature in order for this to work.
    @@ -28,7 +36,13 @@ win = new BrowserWindow({
    });
    ```

    Now all you need to do is import the `sticky-shim.js` file, and add the `sticky-shim` class to any elements which have the `position: sticky` css rule applied.
    Now all you need to do is import `electron-sticky-shim` (or manually include the `sticky-shim.js` file), and add the `sticky-shim` class to any elements which have the `position: sticky` css rule applied.

    ```js
    require('electron-sticky-shim');

    // ...
    ```

    The shim does not automatically add `position: sticky` to your sticky elements, this is so when Electron does support it natively, you can simply remove the shim and the shim class, and your CSS should work as intended.

  3. jmshal revised this gist Jan 3, 2017. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,6 @@

    This 8 line shim makes elements with `position: sticky` work as intended in situations where you have scrollable content nested within your app - see [this](https://twitter.com/heyimjacooob/status/816124902453350400) for an example.

    Before going any further, this is to be used only with Electron.

    ## How do I use it?

    You will need to enable the `position: sticky` flag/blink feature in order for this to work.
  4. jmshal revised this gist Jan 3, 2017. 2 changed files with 6 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # sticky-shim
    # electron-sticky-shim

    This 8 line shim makes elements with `position: sticky` work as intended in situations where you have scrollable content nested within your app - see [this](https://twitter.com/heyimjacooob/status/816124902453350400) for an example.

    5 changes: 5 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    {
    "name": "electron-sticky-shim",
    "version": "0.0.0",
    "main": "sticky-shim.js"
    }
  5. jmshal revised this gist Jan 3, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    This 8 line shim makes elements with `position: sticky` work as intended in situations where you have scrollable content nested within your app - see [this](https://twitter.com/heyimjacooob/status/816124902453350400) for an example.

    Before going any further, this is to be used only in Electron.
    Before going any further, this is to be used only with Electron.

    ## How do I use it?

  6. jmshal revised this gist Jan 3, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,9 @@ win = new BrowserWindow({
    });
    ```

    Now all you need to do is import the `sticky-shim.js` file, and add the `sticky-shim` class to any elements which have the `position: sticky` css rule applied. The shim does not automatically add `position: sticky` to your sticky elements, this is so when Electron does support it natively, you can simply remove the shim and the shim class, and your CSS should work as intended.
    Now all you need to do is import the `sticky-shim.js` file, and add the `sticky-shim` class to any elements which have the `position: sticky` css rule applied.

    The shim does not automatically add `position: sticky` to your sticky elements, this is so when Electron does support it natively, you can simply remove the shim and the shim class, and your CSS should work as intended.

    ## License

  7. jmshal revised this gist Jan 3, 2017. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -30,4 +30,8 @@ win = new BrowserWindow({
    });
    ```

    Now all you need to do is import the `sticky-shim.js` file, and add the `sticky-shim` class to any elements which have the `position: sticky` css rule applied. The shim does not automatically add `position: sticky` to your sticky elements, this is so when Electron does support it natively, you can simply remove the shim and the shim class, and your CSS should work as intended.
    Now all you need to do is import the `sticky-shim.js` file, and add the `sticky-shim` class to any elements which have the `position: sticky` css rule applied. The shim does not automatically add `position: sticky` to your sticky elements, this is so when Electron does support it natively, you can simply remove the shim and the shim class, and your CSS should work as intended.

    ## License

    WTFPL - http://www.wtfpl.net/txt/copying
  8. jmshal revised this gist Jan 3, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -30,4 +30,4 @@ win = new BrowserWindow({
    });
    ```

    Now all you need to do is import the `sticky-shim.js` file, and add the `sticky-shim` class to any elements which have the `position: sticky` css rule applied. The shim does not automatically add `position: sticky`, this is so when Electron does support it natively, you can simply remove the shim and the shim class, and all should work as intended.
    Now all you need to do is import the `sticky-shim.js` file, and add the `sticky-shim` class to any elements which have the `position: sticky` css rule applied. The shim does not automatically add `position: sticky` to your sticky elements, this is so when Electron does support it natively, you can simply remove the shim and the shim class, and your CSS should work as intended.
  9. jmshal revised this gist Jan 3, 2017. 1 changed file with 33 additions and 0 deletions.
    33 changes: 33 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # sticky-shim

    This 8 line shim makes elements with `position: sticky` work as intended in situations where you have scrollable content nested within your app - see [this](https://twitter.com/heyimjacooob/status/816124902453350400) for an example.

    Before going any further, this is to be used only in Electron.

    ## How do I use it?

    You will need to enable the `position: sticky` flag/blink feature in order for this to work.

    You can do this by either adding `CSSStickyPosition` to the `blinkFeatures` web preference...

    ```js
    win = new BrowserWindow({
    // ...
    webPreferences: {
    blinkFeatures: 'CSSStickyPosition',
    },
    });
    ```

    Or you can enable all of the Chrome experimental features (of which `position: sticky` is one)...

    ```js
    win = new BrowserWindow({
    // ...
    webPreferences: {
    experimentalFeatures: true,
    },
    });
    ```

    Now all you need to do is import the `sticky-shim.js` file, and add the `sticky-shim` class to any elements which have the `position: sticky` css rule applied. The shim does not automatically add `position: sticky`, this is so when Electron does support it natively, you can simply remove the shim and the shim class, and all should work as intended.
  10. jmshal created this gist Jan 3, 2017.
    8 changes: 8 additions & 0 deletions sticky-shim.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    window.addEventListener('scroll', (event) => {
    const stickyShim = event.target.querySelector('.sticky-shim');
    if (stickyShim) {
    stickyShim.style.position = 'relative';
    stickyShim.offsetHeight;
    stickyShim.style.position = '';
    }
    }, true);