On window scroll add/remove class with jquery !

window scroll add remove class sticky header by jquery

Sometime we want to add class to particular div to make some changes on the page according to that class .  Mostly this situation is happened when we want make our website header sticky or to fix the header at top of the page.

So here is the jquery Scipt

jQuery(window).scroll(function() {
   var scroll = jQuery(window).scrollTop();

   if (scroll >= 200) { 
    jQuery(".nstHeader").addClass("sticky");
    } 
   else {
    jQuery(".nstHeader").removeClass("sticky");
    }

 }); 

In this script , class will added after scroll the window to 200px. You can change the number as per your condition.

 

If this help you then.. Can you buy a Cup of Coffee for me by nst webcreation paypal--OR-- nst webcreation blog coffee cup

Published by

NST

Myself Narender Singh Thakur ( NST ) and i share my Experience/Knowledge and Tricks for folks and beginners to solve their issues while making websites through this Planet.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Click to Chat