Detect if user is scrolling

后端 未结 4 1682
清酒与你
清酒与你 2020-11-30 22:59

How can I detect in javascript if the user is scrolling?

4条回答
  •  盖世英雄少女心
    2020-11-30 23:19

    this works:

    window.onscroll = function (e) {  
    // called when the window is scrolled.  
    } 
    

    edit:

    you said this is a function in a TimeInterval..
    Try doing it like so:

    userHasScrolled = false;
    window.onscroll = function (e)
    {
        userHasScrolled = true;
    }
    

    then inside your Interval insert this:

    if(userHasScrolled)
    {
    //do your code here
    userHasScrolled = false;
    }
    

提交回复
热议问题