J
J
jeka-32018-02-19 12:27:41
JavaScript
jeka-3, 2018-02-19 12:27:41

How to make a fixed menu work not at a given size, but at 0?

There is a script:

$(function(){
          $(window).scroll(function() {
          var top = $(document).scrollTop();
          if (top < 160) $(".menu-fixed").css({top: '0', position: 'relative',});
          else $(".menu-fixed").css({top: '0', position: 'fixed'});
          });
          });

The menu is under the main screen, and when we get to it, it sticks on the screen, and not through a certain size, as for example here at 160 px.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton fon Faust, 2018-02-19
@bubandos

if(top < $(".menu-fixed").offset()) {
//дальше все то же самое
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question