I've made a website using pagepiling.js, this script adds the class 'active' on the section which is in the viewport. Now I want add a class on my body when my section1 is active like this:
$(document).ready(function() {
if ($('#section1').hasClass("active") === true) {
$('body').toggleClass("one");
}
});
It is working well (the class is added on the body) but when I scroll my section1 does not have the class active because I am now on section2, the class on the body is not removed. How can I fix it? I also tried:
$(document).ready(function() {
if ($('#section1').hasClass('active')) {
$('body').addClass('one');
}
else {
$('body').removeClass('one');
}
});
But it is not working.
You have to put your condition inside scroll event because you should check every time the user scroll :
Hope this helps.