Javascript Scroll Handler not firing

前端 未结 4 1519
攒了一身酷
攒了一身酷 2021-02-12 12:56

All I\'m trying to do is to call a function when a DIV is scrolled.For simplicity sake Im not specifying anything else. Also I am only looking at DOM compliant brow

4条回答
  •  不要未来只要你来
    2021-02-12 13:39

    It happened because your div has height: 100% or height: 100vh. In that case, the scroll event will disable automatically if you gave height:

    Remove that div height, Remove any height on its parent, child. Basically, that particular div should scroll not its parent or child.

    then this should work.

    const AppWrapper = document.getElementById('app-content');
    AppWrapper.removeEventListener('scroll', toggleVisibility);
    
    
    toggleVisibility = () => {
       console.log('Do your thg');
    };
    

提交回复
热议问题