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.