Skip to content

Instantly share code, notes, and snippets.

@ericandrewlewis
Last active September 2, 2024 13:09
Show Gist options
  • Select an option

  • Save ericandrewlewis/1f0424858b389c7ad7531ebba4fa3b30 to your computer and use it in GitHub Desktop.

Select an option

Save ericandrewlewis/1f0424858b389c7ad7531ebba4fa3b30 to your computer and use it in GitHub Desktop.

Revisions

  1. ericandrewlewis revised this gist Jul 31, 2017. No changes.
  2. ericandrewlewis revised this gist Jul 31, 2017. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,5 @@
    # Scroll to the rock bottom of a website

    <img src="https://gist.github.com/ericandrewlewis/1f0424858b389c7ad7531ebba4fa3b30/raw/33d8076d9187fd92bf8bcc6b21bd3b8287259702/z_example.gif">


    Throw the script below in the browser's JS console.

    It moves the viewport to the bottom of the page repeatedly with a delay in between. This is useful when the page loads data via infinite scroll and you want to do something with all the data.
  3. ericandrewlewis revised this gist Jul 31, 2017. 1 changed file with 0 additions and 0 deletions.
    Binary file removed z_example.gif
    Binary file not shown.
  4. ericandrewlewis revised this gist Jul 31, 2017. 2 changed files with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    # Scroll to the rock bottom of a website

    <img src="https://gist.github.com/ericandrewlewis/1f0424858b389c7ad7531ebba4fa3b30/raw/33d8076d9187fd92bf8bcc6b21bd3b8287259702/z_example.gif">


    Throw the script below in the browser's JS console.

    It moves the viewport to the bottom of the page repeatedly with a delay in between. This is useful when the page loads data via infinite scroll and you want to do something with all the data.
    Binary file modified z_example.gif
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  5. ericandrewlewis renamed this gist Jul 31, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes
  6. ericandrewlewis revised this gist Jul 31, 2017. 1 changed file with 0 additions and 0 deletions.
    Binary file added example.gif
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  7. ericandrewlewis revised this gist Jul 31, 2017. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    If you want to scroll to the bottom of a website throw this in the JavaScript console.
    # Scroll to the rock bottom of a website

    It will move the viewport to the bottom of the page repeatedly with a delay in between. This is useful when the page is loading data via infinite scroll and you want to do something after all the data loads.
    Throw the script below in the browser's JS console.

    It moves the viewport to the bottom of the page repeatedly with a delay in between. This is useful when the page loads data via infinite scroll and you want to do something with all the data.

    ```js
    const atPageBottom = () => {
  8. ericandrewlewis revised this gist Jul 31, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    If you want to scroll to the bottom of a website with infinite scroll, throw this in the JavaScript console.
    If you want to scroll to the bottom of a website throw this in the JavaScript console.

    It will move the viewport to the bottom of the page repeatedly with a delay in between. This is useful when the page is loading data via infinite scroll and you want to do something after all the data loads.

    ```js
    const atPageBottom = () => {
  9. ericandrewlewis created this gist Jul 31, 2017.
    25 changes: 25 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    If you want to scroll to the bottom of a website with infinite scroll, throw this in the JavaScript console.

    ```js
    const atPageBottom = () => {
    const scrolled = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
    const documentHeightMinusOneViewport =
    document.body.scrollHeight - Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
    return Math.abs( documentHeightMinusOneViewport - scrolled ) < 3;
    }

    const scrollUntilAtPageBottom = () => {
    if (atPageBottom()) {
    return Promise.resolve(true);
    }
    window.scrollTo(0, document.body.scrollHeight);
    return (new Promise((resolve, reject) => {
    setTimeout(() => {
    resolve(true);
    }, 1000)
    }))
    .then(scrollUntilAtPageBottom);
    }

    scrollUntilAtPageBottom();
    ```