The scroll event, which adds a class when scrolling the area, doesn’t work on mobile

  javascript

I ask for help 🙁

When scrolling down the screen, a class is added to the top title box when it is at a specific box position.
On the desktop, it is added. But mobile doesn’t work.
What should I do?

http://client.1-2-3-4-5.studio/dy/dy/philosophy

$(function() {
var people = $('#section1').position().top;
var book = $('#section2').position().top - 200;
var value = $('#section3').position().top - 200;
// contact = $('#contact').position().top - 700;

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

        if (scroll < book) 
        {
          $("#topmenu-section1").removeClass("active");
          $("#topmenu-section2").addClass("active");
          $("#topmenu-section3").addClass("active");
        } 
        else if (book <= scroll && scroll< value) 
        {
          $("#topmenu-section1").addClass("active");
          $("#topmenu-section2").removeClass("active");
          $("#topmenu-section3").addClass("active");
        } 
        else if (value <= scroll) 
        {
          $("#topmenu-section1").addClass("active");
          $("#topmenu-section2").addClass("active");
          $("#topmenu-section3").removeClass("active");
        }
    });
})

Source: Ask Javascript Questions

LEAVE A COMMENT