There is such a code.
<section class="header"> Шапка </section> <!--//шапка--> <!--***МЕНЮ***--> <section class="main-menu"> Меню </section> When scrolling down, how to make it so that would be fixed at the top of the page?
Шапка There is such a code. When scrolling down, how to make it so that would be fixed at the top of the page? The easiest option, something like this: position: fixed on the menu block / header. It is also useful to give it a z-index more, so that new elements do not fit on the cap. If the menu doesn't stick to the ceiling, use top: 0px. those. Source: https://ru.stackoverflow.com/questions/613350/<section class="header"> Шапка </section> <!--//шапка--> <!--***МЕНЮ***--> <section class="main-menu"> Меню </section> 2 answers 2
$(window).on('scroll', function(e) { var $header = $('.header'), $menu = $('.main-menu'), scroll = $(this).scrollTop(); if (scroll >= $header.height()) { $menu.addClass('fixed'); } else { $menu.removeClass('fixed'); } });
body { height: 1000px; } .header { background: #eee; height: 80px; } .main-menu { width: 100%; height: 30px; background: #f00; } .main-menu.fixed { position: fixed; top: 0; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <section class="header"> Шапка </section> <!--//шапка--> <!--***МЕНЮ***--> <section class="main-menu"> Меню </section>
.header { position:fixed; top:0px; z-index:9999; } More articles:
All Articles