0

I have a page whose body is scrolling. That is, a scroll event listener on body works. However, scroll listeners on window and document does not fire.

The problem is, even though body is scrolling, $("body").scrollTop() returns 0 all the time. I looped through ALL the children of body and none of them has scrollTop() greater than 0. Some of the children has overflow: hidden but that should not affect scrollTop I guess.

I removed height: 100% as per this question and I've also gone through this question.

And I made sure it is indeed body that is scrolling by setting its overflow as hidden - the scroll bar disappeared. And I also tried attaching scroll listeners on every container div in the application - none of them fired. So it is indeed the body that is scrolling and for some weird reason jquery scrollTop() returns 0 for all the elements.

And yes, I tried accessing document.body.scrollTop - still 0.

Any hints as to what might be causing this issue will be received with a LOT of gratitude. Been stuck here for a while. Thanks :)

EDIT: document.documentElement.scrollTop also returns 0. $(document).scrollTop() - returns 0. !DOCTYPE html is also set.

EDIT 2: Strangely enough, I can't also scroll by setting scrollTop on body. That is, $('body').scrollTop(500) does nothing!

EDIT 3:: My jquery function:

$("body").on("scroll", function(){
    var children = $("body").children();
    $("body").scrollTop(800);
    for(var i=0; i<children.length; i++){
        if($(children[i]).scrollTop() > 0){
            console.log("children: " + i);
            console.log("val: " + $(children[i]).scrollTop());
        }
    }
});
Community
  • 1
  • 1

1 Answers1

0

There was a height: 100% coming from another css file. Solved it by setting height: auto.