I have a bttn (".medianavbttn") which shows/hides a div (".medianav"). My webpage is for mobile devices and as the display:fixed
css code does not work on them, i use jquery sticky navigation instead, so i stick it on the top of the page.
As i want to stick the navigation also, not only the button, i must display: hidden
the "medianav" too. The problem is that in this case, the height of its virtual wrapper will appear without any content, so it pushes my page downer and it is ugly.
Instead of hiding the "medianav", i made the virtual wrapper display: hidden
, so the navigation height is OK now. BUT : as the virtual wrapper is not visible immediately, when i open the navigation, the slide toggle "swing" animation is not smooth.
Can someone tell me how i can animate it smooth ? Or if it is not possible, which methode should i use for scrolling the navigation in and out of the page with a click of the sticked button ?
The HTML
<div class="medianavbttn">Show Menu</div>
<div class="medianav">
<ul id="medianav-links">
<li class="current"><a href="#section1">About</a></li>
<li><a href="#section2">Gallery Photos</a></li>
<li><a href="#section3">Contact</a></li>
</ul>
</div>
The Scripts
<!-- Nav Sticky Effect -->
<script>
$(window).load(function(){
$(".medianavbttn").sticky({ topSpacing: 0, className: 'sticky', wrapperClassName: 'navbttn-wrapper' });
});
$(window).load(function(){
$(".medianav").sticky({ topSpacing: 0, className: 'sticky', wrapperClassName: 'nav-wrapper' });
});
</script>
<!-- Show - Hide Content -->
<script>
$(".medianavbttn").on("click", function(){
$(".nav-wrapper").slideToggle("slow");
$(this).text($(this).text() == "Show Menu" ? "Hide Menu" : "Show Menu");
});
</script>
The CSS
.medianavbttn {
position: relative;
display:block;
width: 100%;
height: 30px;
top: 0;
left: 0;
margin: 0;
padding: 5px 0 5px;
text-align: center;
cursor: pointer;
z-index: 999;
}
#mediabody .nav-wrapper {
display: none;
height: auto;
}
.medianav {
position: relative;
display: block;
width: 100%;
padding: 35px 0 5px;
text-align: center;
z-index: 998;
}
#medianav-links {
position: relative;
display: block;
overflow: visible;
width: 100%;
text-align: center;
list-style: none;
z-index: 997;
}
#medianav-links li {
width: 60%;
height: 30px;
position: relative;
display: block;
margin: 2% auto 0;
padding: 5px;
text-align: center;
}