You can use .on("update", function() { … }
in your scene.
Here's something I just did for a new page. The tweened '#header' is inside another DIV that has position: fixed
, is twice as high as '#header' and top: -80px;
, so header
is moved 80px up or down (i.e. in and out of the visible area), depending on the scroll direction:
var controller = new ScrollMagic.Controller();
var i1 = 0;
var i2 = 0;
var scene = new ScrollMagic.Scene()
.addTo(controller)
.on("update", function() {
var x1 = controller.info("scrollDirection");
var x2 = $(window).scrollTop();
var x3 = 400;
if ( x1 == "REVERSE" && x2 >= x3 && i1 == 0) {
TweenLite.fromTo("#header", 0.3, {top: "0px"}, {top: "80px", ease: Linear.easeNone});
i1++;
i2 = 0;
}
if ( x1 == "FORWARD" && x2 > x3 && i2 == 0) {
TweenLite.fromTo("#header", 0.3, {position: "absolute", top: "80px"}, {top: "0px", ease: Linear.easeNone});
i1 = 0;
i2++;
}
});
i1
and i2
are used to filter redundant events to avoid multiple tweens in the same direction.
x3 defines how long the header remains visible at the top of the page.