How to trigger an on scroll event without scrolling

前端 未结 8 1223
梦毁少年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条回答
  • 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.

    0 讨论(0)
  • 2021-02-12 04:18

    A litle bit off topic:

    You dont need to use the dev tools just create a bookmark with the folowing "url"

        javascript:(function(){
            /*  Put your code here, e.g. the scrollng event  or add an 
               event listener to the current page or some other code*/
        })();
    

    when you click this bookmark, the cod will be executed, inside the current page's environment

    0 讨论(0)
提交回复
热议问题