Detect if a scroll event is triggered manually in jQuery

后端 未结 7 1131
执念已碎
执念已碎 2021-01-11 13:21

This question was already asked here a long time ago:

Detect jquery event trigger by user or call by code

But it has never been answered conclusively (or m

7条回答
  •  爱一瞬间的悲伤
    2021-01-11 13:38

    Maybe :animated selector will help you:

    $('#scroller').scroll(function(e) {
        if ($(this).is(':animated')) {
            console.log('scroll happen by animate');
        } else if (e.originalEvent) {
            // scroll happen manual scroll
            console.log('scroll happen manual scroll');
        } else {
            // scroll happen by call
            console.log('scroll happen by call');
        }
    });
    

    Demo

提交回复
热议问题