jQuery scroll() detect when user stops scrolling

前端 未结 13 1464
情歌与酒
情歌与酒 2020-11-22 02:17

Ok with this..

$(window).scroll(function()
{
    $(\'.slides_layover\').removeClass(\'showing_layover\');
    $(\'#slides_effect\').show();
});
13条回答
  •  被撕碎了的回忆
    2020-11-22 02:59

    I agreed with some of the comments above that listening for a timeout wasn't accurate enough as that will trigger when you stop moving the scroll bar for long enough instead of when you stop scrolling. I think a better solution is to listen for the user letting go of the mouse (mouseup) as soon as they start scrolling:

    $(window).scroll(function(){
        $('#scrollMsg').html('SCROLLING!');
        var stopListener = $(window).mouseup(function(){ // listen to mouse up
            $('#scrollMsg').html('STOPPED SCROLLING!');
            stopListner(); // Stop listening to mouse up after heard for the first time 
        });
    });
    

    and an example of it working can be seen in this JSFiddle

提交回复
热议问题