Javascript Scroll Handler not firing

前端 未结 4 1515
攒了一身酷
攒了一身酷 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:37

    This is because the window is scrolling not the div. Try changing your element listener to the parent of the div (in this case the window) like this.

    window.addEventListener("scroll", function () {
        myFunc();
    }, false);
    

提交回复
热议问题