Skip to content

Instantly share code, notes, and snippets.

@kodie
Last active January 9, 2025 18:47

Revisions

  1. kodie revised this gist Jan 9, 2025. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions stickyFooter.js
    Original file line number Diff line number Diff line change
    @@ -15,5 +15,5 @@ var stickyFooter = function () {
    }
    }

    window.addEventListener('load', stickyFooter)
    window.addEventListener('resize', stickyFooter)
    window.addEventListener('load', stickyFooter);
    window.addEventListener('resize', stickyFooter);
  2. kodie created this gist Jan 9, 2025.
    19 changes: 19 additions & 0 deletions stickyFooter.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    // Ensures the highest the footer will ever be on the screen is the bottom of the viewport
    var stickyFooter = function () {
    var footer = document.querySelector('footer')

    if (window.innerHeight > document.body.scrollHeight) {
    footer.style.bottom = 0
    footer.style.left = 0
    footer.style.position = 'fixed'
    footer.style.right = 0
    } else {
    footer.style.bottom = null
    footer.style.left = null
    footer.style.position = null
    footer.style.right = null
    }
    }

    window.addEventListener('load', stickyFooter)
    window.addEventListener('resize', stickyFooter)