• Skip to primary navigation
  • Skip to main content
Matthew Dunbar

Matthew Dunbar

Hire Me
  • About
  • Portfolio
  • Blog
    • General
    • HTML
    • jQuery
    • PHP
    • Optimization
  • Hire Me
You are here: Home / Archives for Learning

Learning

How to Add A Class to Header on Scroll with jQuery

February 17, 2017


var header = $(".header");
    $(window).scroll(function() {
        var scroll = $(window).scrollTop();
        if (scroll >= 300) {
            header.addClass("scrolled");
        } else {
            header.removeClass("scrolled");
        }
    });

Filed Under: jQuery, Learning

  • Page 1
  • Page 2
  • Page 3
  • Interim pages omitted …
  • Page 13
  • Go to Next Page »
© 2025 Matthew Dunbar - All Rights Reserved Back to Top