How to trigger an on scroll event without scrolling

前端 未结 8 1241
梦毁少年i
梦毁少年i 2021-02-12 03:15

my Question is, how can i trigger (simulate or something esle) an on scroll event. In my special case I don\'t want to load all the Conservations in LinkedIn by scolling down al

8条回答
  •  猫巷女王i
    2021-02-12 04:11

    This doesn't work on Chrome or Firefox

    window.scrollTo(window.scrollX, window.scrollY);
    

    This works on both:

    window.scrollTo(window.scrollX, window.scrollY - 1);
    window.scrollTo(window.scrollX, window.scrollY + 1);
    

    Not fancy, but works.

    Note that only the first line of code is necessary, the other one is just to return the scroll back to where it was. I had to trigger a scroll function on a button. If you happen to tap the button twice, the effect of the scroll is visible and it's not very fancy. That's why I prefer adding the 2nd line of code as well.

提交回复
热议问题