need to show nava
if wrapt
is not visible by scrolling the page
and vice versa - hide the nava
if wrapt
is visible
what is wrong with this JS code ?
let io = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if(entry.isIntersecting){modify(entry.target);}
else{revert(entry.target);}
});
});
function modify(el){
if(el.id == "wrapt"){$(nava).slideUp();}
}
function revert(el){
if(el.id == "wrapt"){$(nava).slideDown();}
}
$(document).ready(function(){
io.observe(document.querySelector('#wrapt'));
});
.nava{
display:none
height:25px;
background:orange;
position:relative;
z-index:9;
}
.wrapt{
height:54px;
background:lightblue;
}
.story{
height:200vh;
background:#ddd;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='nava' id='nava'></div>
<div class='wrapt' id='wrapt'></div>
<div class='story'></div>