Detect jquery event trigger by user or call by code

后端 未结 2 1915
情深已故
情深已故 2020-12-28 22:45

I have some window.onscroll event

$(window).scroll(function(e){
    //My Stuff
});

but in my code I call animate scroll to som

相关标签:
2条回答
  • 2020-12-28 23:14
    $('#scroller').scroll(function(e) {
        if (e.originalEvent) {
            // scroll happen manual scroll
            console.log('scroll happen manual scroll');
        } else {
            // scroll happen by call
            console.log('scroll happen by call');
        }
    });
    
    $('#scroller').scroll(); // just a initial call
    

    When you scroll by call the e.originalEvent will undefined but when scroll manually it will give scroll object.

    DEMO

    0 讨论(0)
  • 2020-12-28 23:29

    ive reasked this question and got 2 helpful answers.
    i'll link the question here for others who'll find this thread.

    Detect if a scroll event is triggered manually in jQuery

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