jQuery scroll() detect when user stops scrolling

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

Ok with this..

$(window).scroll(function()
{
    $(\'.slides_layover\').removeClass(\'showing_layover\');
    $(\'#slides_effect\').show();
});
13条回答
  •  遇见更好的自我
    2020-11-22 02:38

    You could set an interval that runs every 500 ms or so, along the lines of the following:

    var curOffset, oldOffset;
    oldOffset = $(window).scrollTop();
    var $el = $('.slides_layover'); // cache jquery ref
    setInterval(function() {
      curOffset = $(window).scrollTop();
      if(curOffset != oldOffset) {
        // they're scrolling, remove your class here if it exists
        if($el.hasClass('showing_layover')) $el.removeClass('showing_layover');
      } else {
        // they've stopped, add the class if it doesn't exist
        if(!$el.hasClass('showing_layover')) $el.addClass('showing_layover');
      }
      oldOffset = curOffset;
    }, 500);
    

    I haven't tested this code, but the principle should work.

提交回复
热议问题