jQuery scroll() detect when user stops scrolling

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

Ok with this..

$(window).scroll(function()
{
    $(\'.slides_layover\').removeClass(\'showing_layover\');
    $(\'#slides_effect\').show();
});
13条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 03:01

    Ok this is something that I've used before. Basically you look a hold a ref to the last scrollTop(). Once your timeout clears, you check the current scrollTop() and if they are the same, you are done scrolling.

    $(window).scroll((e) ->
      clearTimeout(scrollTimer)
      $('header').addClass('hidden')
    
      scrollTimer = setTimeout((() ->
        if $(this).scrollTop() is currentScrollTop
          $('header').removeClass('hidden') 
      ), animationDuration)
    
      currentScrollTop = $(this).scrollTop()
    )
    

提交回复
热议问题