Add bottom box shadow to the menu on scrollup and scrolldown

后端 未结 2 710

I have a menu with this CSS properties:

#header {
  width: 100%;
  position: fixed;
  z-index: 9000;
  overflow: auto;
}
         


        
2条回答
  •  别跟我提以往
    2021-02-19 17:39

    Create a class called shadow to add to your header div on window.scroll.

    http://jsfiddle.net/43aZ4/

    var top = $('#header').offset().top;
      $(window).scroll(function (event) {
        var y = $(this).scrollTop(); 
        if (y >= 60) {  $('#header').addClass('shadow'); }
        else { $('#header').removeClass('shadow'); }
      });
    
    .shadow {
        -webkit-box-shadow: 0px 10px 5px rgba(50, 50, 50, 0.75);
        -moz-box-shadow:    0px 10px 5px rgba(50, 50, 50, 0.75);
        box-shadow:         0px 10px 5px rgba(50, 50, 50, 0.75);
    }
    

提交回复
热议问题