When scrolling down the page, the slide up is fired but the sticky wrapper does not adjust to the missing height of the slid up element. Is stays there and keeps the content from coming up. How can I adjust the height of the sticky-wrapper according to the height of the slid up elements?
http://jsfiddle.net/Luter/1/ Comment out the first //$('.option-wrap').slideToggle(); (case b) click on Menu and scroll down. The Menu element this time is only sticky when it has scrolled past the height of the Header. Again, how could I adjust the sticky wrapper height for the missing Header, so that the Menu is stuck immediately?
Do these two cases have to do with offset or with refreshing the sticky wrapper? I think, since Waypoints correctly measures the height of the initial state of the whole Menu/window element the sticky wrapper keeps its height even when Options are slid up partly or when the Header is hidden.
I am looking for a way to pass the smaller sticky wrapper height to Waypoints according to the slide/visible/toggle state of the Options element or hidden Header element.
I have trouble wrapping my head round how to pass the missing height of the slid up or hidden elements to Waypoints so that the content always nicely flows under the Menu.
I have checked tutsplus, Waypoints Docs, Sticky Elements, stack different-offset-for-jquery-waypoint, stack how-to-make-jquery-waypoints-plugin-fire-when and tried many different combinations but simply do not get there.
Can you please help me? Thank you for your time, I do value the Waypoints plugin highly and learning to correctly work with it with your help would be great. Thank you.
HTML
<div id='header'>HEADER</div>
<div id='menu-wrap'>
<div id='menu'>MENU</div>
<div class='option-wrap'>
<div id='opt1'>OPTION 1</div>
<div id='opt2'>OPTION 2</div>
<div id='opt3'>OPTION 3</div>
<div id='opt4'>OPTION 4</div>
</div>
</div>
<div id='content'>CONTENT</div>
jQuery
$('#menu-wrap').waypoint('sticky');
$(function() {
$('#menu').waypoint(
function() {
console.log("Waypoint reached.");
//case b
//$('.option-wrap').slideToggle();
}
)
});
$("#menu").click(function(){
$('.option-wrap').slideToggle();
$('#header').slideToggle('slow');
});
CSS
#header, #menu, #opt1, #opt2, #opt3, #opt4, #opt5, #content {
width: 100%;
line-height: 2em;
font-size: 200%;
text-align: center;
}
#header {
background: #e74c3c;
}
#menu {
background: #2ecc71;
}
#opt1 {
background: #f39c12;
}
#opt2 {
background: #9b59b6;
}
#opt3 {
background: #95a5a6;
}
#opt4 {
background: #34495e;
}
#content {
background: #2980b9;
height: 1000px;
}
#menu-wrap.stuck {
position: fixed;
top: 0;
width: 100%;
}