I'm working on a website that the HTML menu is not changeable. I want when the user scrolls the scroll bar up to the menu bar, it becomes fixed at the top of the page, respecting the distance of another bar that is working and is already set automatically.
MENU HTML (Not changeable):
<nav class="menu_component" id="component_37548">
<div class="menu-head">
<span>
Menu
</span>
<button class="hamburger hamburger--spin-r" type="button">
<span class="hamburger-box">
<span class="hamburger-inner">
</span>
</span>
</button>
</div>
<div class="menu-panel">
<menu class="expanded hamburger-menu">
<li id="menu_item_39037" class="sub">
<a alt="O SIENPRO" title="" target="" class="empty-href">
O SIENPRO
</a>
<menu class="submenu">
<li id="menu_item_41614" class="">
<a alt="SOBRE" title="" target="" class="" href="/p/21374-sobre-o-sienpro">
SOBRE
</a>
</li>
<li id="menu_item_39038" class="">
<a alt="COMITÊ" title="" target="" class="" href="/p/23834-comite-2018">
COMITÊ
</a>
</li>
</menu>
</li>
<li id="menu_item_41615" class="">
<a alt="TEMA" title="" target="" class="" href="https://sienpro.catalao.ufg.br/#tema">
TEMA
</a>
</li>
<li id="menu_item_41616" class="">
<a alt="PRINCIPAIS DATAS" title="" target="" class="" href="https://sienpro.catalao.ufg.br/#datas">
PRINCIPAIS DATAS
</a>
</li>
<li id="menu_item_39040" class="sub">
<a alt="EDIÇÕES SIENPRO" title="" target="" class="empty-href">
EDIÇÕES SIENPRO
</a>
<menu class="submenu">
<li id="menu_item_41593" class="">
<a alt="I SIENPRO - 2017" title="" target="" class="" href="/p/23811-i-sienpro-2017">
I SIENPRO - 2017
</a>
</li>
<li id="menu_item_41605" class="">
<a alt="II SIENPRO - 2018" title="" target="" class="" href="/p/23814-ii-sienpro-2018">
II SIENPRO - 2018
</a>
</li>
</menu>
</li>
<li id="menu_item_39041" class="">
<a alt="CONTATO" title="" target="" class="" href="https://sienpro.catalao.ufg.br/#contato">
CONTATO
</a>
</li>
<li id="menu_item_41617" class="sub">
<a alt="ARTIGOS" title="" target="" class="empty-href">
ARTIGOS
</a>
<menu class="submenu">
<li id="menu_item_41618" class="">
<a alt="REGRAS PARA SUBMISSÃO" title="" target="" class="empty-href">
REGRAS PARA SUBMISSÃO
</a>
</li>
<li id="menu_item_41619" class="">
<a alt="ORIENTAÇÃO PARA APRESENTAÇÃO" title="" target="" class="empty-href">
ORIENTAÇÃO PARA APRESENTAÇÃO
</a>
</li>
</menu>
</li>
<li id="menu_item_41620" class="">
<a alt="PROGRAMAÇÃO" title="" target="" class="empty-href">
PROGRAMAÇÃO
</a>
</li>
<li id="menu_item_41621" class="">
<a alt="LOCAL" title="" target="" class="empty-href">
LOCAL
</a>
</li>
</menu>
</div>
Fixing Variable CSS:
.fixar{
position: fixed;
width: 100%;
top: 37px;
z-index: 999;
}
Javascript to try to fix the menu:
jQuery("document").ready(function($){
var offset = $('.menu_component').offset().top;
var nav = $('.menu_component');
$(document).on('scroll', function () {
if (offset <= $(window).scrollTop()) {
nav.addClass('fixar');
} else {
nav.removeClass('fixar');
}
});
});
I thought the Javascript was right, but it's not working at all. Link to the site: link
I do not know if it's a class I'm trying to change that is wrong, whether it's a class of <nav>
, <div>
, or <menu>
that I have to change with javascript,
or if it has to be a cascade between all of them.