This is the rough structure of my website:
<header>
<section1>
<section2>
<section3>
<footer>
I'm using a ScrollMagic scene to pin my header until section2 gets to the top of the window.
To achieve that I set the duration of the scene to the header's height + section1 height.
The problem is that ScrollMagic creates a div element around my header with a padding-bottom of exactly that duration.
But I don't want that padding. I would like the header to be right on top of section1 and once I start scrolling to act as if it was fixed - but only until I get to section 2. At the moment section 2 gets to the top of the window (minus the header height) I want the scene to end and the header to scroll out.
In fact everything works as it should when I set the duration to 0. But obviously that also lets my header stay there the whole time and not disappear once I get to section2.
I hope that was understandable.
Here is my code:
var controller = new ScrollMagic.Controller();
var headerscroll = $("#header").height() + $("#section1").height() ;
var headerScene = new ScrollMagic.Scene({
pushFollowers: false,
duration: headerscroll,
offset: 30
})
.setPin("#header");
controller.addScene([
headerScene
]);