滚动条事件,向下滚动给header加class

曹え 5811 发布于:2022-06-09 00:59:58

$s = $('.header')
$(window).scroll(function(e){
    var w_top = $(window).scrollTop();
    // 导航条固定在屏幕上
    if ( w_top > 50) {
        $s.addClass('header-fixed')
    } else {
        $s.removeClass('header-fixed')
    }
  })


上面的50是是向下滚动的距离,单位是px

觉得有用请点个赞吧!
1 767