Experiencing an issue with adjusting the position of an element by utilizing the margin-top property. The element is located within a bootstrap navigation. The problem arises when the margin changes correctly upon scrolling, but fails to revert back to its original value when scrolling back to the top. Here is the code snippet involved:
$(".flags").css("margin-top", "24px");
$(window).scroll(function(){
var scrollingDiv = $(".flags").offset().top - $(window).scrollTop();
var menuMmainScroll = $(".navbar-nav>li>a").offset().top - $(window).scrollTop();
if(menuMmainScroll === 68) {
$(".flags").css("margin-top", "24px");
}
else /**if(menuMmainScroll < 10)**/ {
$(".flags").css("margin-top", "10px");
}
console.log(menuMmainScroll);
});
<div class="menu_main">
<div class="navbar yamm navbar-default">
<div class="navbar-header">
<div class="navbar-toggle .navbar-collapse .pull-right " data-toggle="collapse" data-target="#navbar-collapse-1" > <span>Menu</span>
<button type="button" > <i class="fa fa-bars"></i></button>
</div>
</div>
<div id="navbar-collapse-1" class="navbar-collapse collapse pull-right">
<nav>
<ul class="nav navbar-nav">
<li class="dropdown"><a href="index_new_fullmenu.html" class="dropdown-toggle active">Home</a>
<ul class="dropdown-menu" role="menu">
<li><a href="index_new_fullmenu.html">Forside</a></li>
<li class="active"><a href="nytilyoga.html">Ny til Yoga</a></li>
<li><a href="#holdplan" data-scroll>Holdplan</a></li>
<li><a href="#priser" data-scroll>Priser</a></li>
<li><a href="#kontakt" data-scroll>Kontakt</a></li>
<li><a href="http://yogagear.dk/">Butik</a></li>
<li><a href="http://memberservice.sport-solutions.dk/">Medlem log ind</a></li>
</ul>
</li>
<li><a href="#holdplan" class="dropdown-toggle">Holdplan</a></li>
<li><a href="#priser" class="dropdown-toggle">Priser</a></li>
<li><a href="nytilyoga.html" class="dropdown-toggle">Ny til yoga</a></li>
<li class="dropdown"><a href="omyoga.html" class="dropdown-toggle">Om Yoga</a>
<ul class="dropdown-menu" role="menu">
<li><a href="mysore.html">Mysore metode</a></li>
<li><a href="omastanga">Om Astanga yoga</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Services</a></li>
</ul>
</li>
<li><a href="mysore.html" class="dropdown-toggle">Mysore</a> </li>
<li><a href="studiet.html" class="dropdown-toggle">Studiet</a></li>
<li><a href="studiet.html" class="dropdown-toggle">Butik</a></li>
<li><div class="dropdown-toggle flags"> !!!!!!!!!!!!!!!!!!!!!!
<a href="#" class="flag-link"><img src="UK_flag.png" alt="English">
</a>
<a href="#" class="flag-link"><img src="DK_flag.png" alt="Danish">
</a>
</div> !!!!!!!!!!!!!!!!!!</li>
</ul>
</nav>
</div>
</div>
Highlighted the problematic area in HTML using !
at both ends. Essentially, there's another menu initially displayed above this one (before scrolling), but once scrolling begins, this menu takes over the top position and remains fixed at the top. The issue arises from using a div containing two images inside two links which are not aligning correctly inline, rather having a gap of 24px between them vertically in a separate field. Your input on this matter would be greatly appreciated.