JavaScript

Add or remove class on scroll down and scroll up

In this tutorial, we learn that how to add or remove class based on scrolls down and scrolls up, when the user scrolls down, gets to a certain amount of pixels it’s attached a new class to a particular DIV and Scroll up again the remove the class form that DIV. Add a class when scrolling down after some height from the top of the page. On mouse scroll down add a div and remove div when mouse scroll up.

Add/remove class on scroll down and scroll up
Add/remove class on scroll down and scroll up

HTML

<div class="box">1</div>
//After scroll down add class box-hover
<div class="box box-hover">1</div>

JavaScript

<script>
$(document).ready(function() {
  $(window).scroll(function(){
      if ($(this).scrollTop() > 50) {
         $('.box').addClass('box-hover');
      } else {
         $('.box').removeClass('box-hover');
      }
  });
});
</script>

Add and remove class on scroll jQuery

Using the jQuery scrollTop() function to find the scroll position and add/remove a class on mouse scroll up or down. Add a class on some particular div on page after scrolling 100px, 500px or end of the page bottom. Adding/Removing particular div based on scrolling position. Sometimes we want to add class to a particular div to make some changes on that div depend on the new change, so we need to add a new class with the new CSS property. Add and remove class with jQuery based on vertical scroll Class Toggles.

The scroll event occurs when the user scrolls down or up on the page or a specified element.

Right now, discover that how to include or expel class on scrolls down and scrolls up, when the user looks down, finds a workable space measure of pixels it’s joined another class to a specific DIV and Scroll up again the evacuate the class structure DIV. Include a class when looking down after some range from the highest point of the page. On mouse look down to add a class and expel div when mouse lookup.

Utilizing the jQuery scrollTop() capacity to discover the parchment position and include/evacuate DIV on mouselook up or down. Include a class some specific div on-page in the wake of looking over 100px, 500px or end of the page base. Including/Removing specific class to a div dependent on looking over the position. Now and again we need to add class to a specific div to roll out certain improvements on that div rely upon new change, so we need to include another class with the new CSS property. Include and expel class with jQuery dependent on vertical parchment Class Toggles.

The parchment occasion happens when the client looks down or up on the page or a predefined component. The parchment () technique triggers the parchment occasion, and as per scroll occasion changes the conduct of components. Parchment JavaScript occasion $(window).scroll (function() { } trigger that occasion on a component.

The jQuery scrollTop() method also use for Hide header navigation on scroll down and show on scroll up, var st = $(this).scrollTop(); The jQuery scrollTop() method sets or returns the vertical scrollbar position for the selected elements. add/remove class when scrolling over section, on scroll add class and remove class jQuery. Add/remove class on scroll down and scroll up.