Check out my current Jsfiddle project here
I am working on a task that involves adding a class to a specific div when scrolling and then removing that class.
Below is the JavaScript code I have written for this functionality:
var targetDiv = $(".mainwrapper");
$(window).scroll(function() {
var scrollPos = $(window).scrollTop();
console.log(scrollPos);
if (scrollPos >= targetDiv.offset().top - 10) {
targetDiv.addClass('fixed');
console.log("Element fixed");
} else {
targetDiv.removeClass('fixed');
console.log("Element not fixed");
}
});