jQuery position DIV fixed at top on scroll

前端 未结 1 491
醉酒成梦
醉酒成梦 2020-11-29 10:01

I have a page that\'s fairly long and within the layout\'s menu, there\'s a flyout menu. I\'d like this flyout portion of the menu to show at the top of the page even when t

相关标签:
1条回答
  • 2020-11-29 10:25

    instead of doing it like that, why not just make the flyout position:fixed, top:0; left:0; once your window has scrolled pass a certain height:

    jQuery

      $(window).scroll(function(){
          if ($(this).scrollTop() > 135) {
              $('#task_flyout').addClass('fixed');
          } else {
              $('#task_flyout').removeClass('fixed');
          }
      });
    

    css

    .fixed {position:fixed; top:0; left:0;}
    

    Example

    0 讨论(0)
提交回复
热议问题