Footer hides floating nav - Any way to slide floating nav up once it reaches the footer?

前端 未结 2 782
挽巷
挽巷 2021-01-28 12:39

I\'m trying to add a floating navigation to the side bar. I have jquery floating the nav to the top after you begin scrolling. It works fine at the top, but once you reach the b

相关标签:
2条回答
  • 2021-01-28 12:59

    Is this like what you're looking for: http://jsfiddle.net/N5AC8/1/

    $(document).ready(function() {
          var top = $('#floatingNav').offset().top - parseFloat($('#floatingNav').css('marginTop').replace(/auto/, 0));
          var maxTop = $(document.body).height() - $('footer').height() - $('#floatingNav').outerHeight();
          $(window).scroll(function(event) {
              var y = $(this).scrollTop();
              console.log(y, maxTop);
              $('#floatingNav').css({
                  position: '',
                  top: ''
              });
              if (y >= maxTop) {
                  $('#floatingNav').css({
                      position: 'absolute',
                      top: maxTop
                  });
              } else if (y >= top) {
                  $('#floatingNav').addClass('fixed');
              } else {
                  $('#floatingNav').removeClass('fixed');
              }
          });
      });
    

    This is not really optimized, but should give you something to work from if it's what you're looking for.

    0 讨论(0)
  • 2021-01-28 13:02

    Give the navigation a higher z-index than the footer. Something like z-index:99; will definitly do it.

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