I am using bootstrap 4 scrollspy and customized affix.Problem is when second menu comes to view i need to remove the first fixed menu. Check the fiddle here https://jsfiddle.net/raj_mutant/awknd20r/ html:
<body data-spy="scroll" data-target=".navbar" data-offset="50">
<header>
<div class="container">
</div>
</header>
<section id="intro">
<div class="container">
<div class="jumbotron">
<div class="container">
<h2>Test</h2>
<h1>Lorem Ipsum</h1>
<h4>Lorem Ipsum</h4>
</div>
</div>
</div>
</section>
<section>
<nav class="tab-menu navbar navbar-expand-sm" data-toggle="affix">
<ul class="navbar-nav">
<li class="nav-link nav-item" href="#section1">
<a href="#">test</a>
</li>
<li class="nav-link nav-item" href="#section2">
<a href="#">test</a>
</li>
<li class="nav-link nav-item" href="#section3">
<a href="#">test</a>
</li>
</ul>
</nav>
<div class="section" id="section1" class="container-fluid bg-success" style="padding-top:70px;padding-bottom:70px">
</div>
<div class="section" id="section2" class="container-fluid bg-danger" style="padding-top:70px;padding-bottom:70px">
</div>
<section>
Need affix element for both top to bottom scroll and vice versa.Thanks in advance.
Instead of a custom affix javascript, I would definitely go with the
.sticky-top
positioning utility of Bootstrap. As far as I understand your question, that covers the functionality you want. Here is a working example:As you see in the example, I've moved the first menu a bit and wrapped it to a
<div>
that spans down until the second menu. This makes the first menu disappear just when the second menu scrolls into view.Also, please note that in order to let the Scrollspy work correctly, use different ids in the first and the second menu (e.g. you had
section1
in both).