2018-01-21 12:56:54 +00:00
|
|
|
//are we running in dev mode?
|
|
|
|
var debug = document.body.getAttribute("data-env") === "development" ? true : false;
|
2018-01-20 23:49:35 +00:00
|
|
|
|
2018-01-21 12:56:54 +00:00
|
|
|
var controllerPanes = new ScrollMagic.Controller({
|
|
|
|
globalSceneOptions: {
|
|
|
|
//triggerHook: 'onLeave'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var controllerAnimations = new ScrollMagic.Controller({
|
|
|
|
globalSceneOptions: {
|
|
|
|
//triggerHook: 'onLeave'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function calculateOffset(){
|
|
|
|
var containerHeight = document.getElementById("pinContainer").offsetHeight;
|
|
|
|
var introHeight = document.getElementById("intro").offsetHeight;
|
|
|
|
var initialOffset = (containerHeight / introHeight * 100);
|
|
|
|
if (initialOffset > 100) {
|
|
|
|
return "-100%";
|
|
|
|
} else {
|
|
|
|
return "-" + Math.floor(initialOffset) + "%";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createTween(section, duration ,index){
|
|
|
|
if (index === 0) {
|
|
|
|
var startY = calculateOffset();
|
|
|
|
} else {
|
|
|
|
var startY = "-0%";
|
|
|
|
}
|
|
|
|
var tween = TweenMax.fromTo(section, duration, {
|
|
|
|
y: startY,
|
|
|
|
}, {
|
|
|
|
y: "-100%",
|
|
|
|
})
|
|
|
|
return tween;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createTweenTimeline(){
|
2018-01-21 10:10:43 +00:00
|
|
|
var sections = document.querySelectorAll("section");
|
|
|
|
var sectionCount = sections.length;
|
|
|
|
var sectionDurations = [];
|
2018-01-20 23:49:35 +00:00
|
|
|
|
2018-01-21 10:10:43 +00:00
|
|
|
for (var i = 0; i < sections.length; i++) {
|
2018-01-21 12:56:54 +00:00
|
|
|
sectionDurations.push(sections[i].offsetHeight/300);
|
2018-01-21 10:10:43 +00:00
|
|
|
}
|
|
|
|
|
2018-01-21 12:56:54 +00:00
|
|
|
var tweens = [];
|
|
|
|
var timeline = new TimelineMax();
|
|
|
|
for (var i = 0; i < sections.length; i++) {
|
|
|
|
tweens.push(createTween(sections[i], sectionDurations[i], i));
|
|
|
|
timeline.add(tweens[i]);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
timeline: timeline,
|
|
|
|
tweens: tweens
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
wipeAnimation = createTweenTimeline();
|
2018-01-21 10:10:43 +00:00
|
|
|
|
2018-01-20 23:49:35 +00:00
|
|
|
|
|
|
|
|
2018-01-21 12:56:54 +00:00
|
|
|
// create scene for every slide
|
|
|
|
//for (var i = 0; i < sections.length - 1; i++) {
|
|
|
|
var triggerElement = document.getElementsByClassName("container")[0];
|
|
|
|
var panelScene = new ScrollMagic.Scene({
|
|
|
|
triggerElement: triggerElement,
|
|
|
|
duration: "400%",
|
|
|
|
triggerHook: "onLeave"
|
|
|
|
})
|
|
|
|
.setPin(triggerElement)
|
|
|
|
.setTween(wipeAnimation.timeline)
|
|
|
|
.addTo(controllerPanes);
|
|
|
|
if (debug) {
|
|
|
|
panelScene.addIndicators()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('resize', function(){
|
|
|
|
wipeAnimation.tweens[0].updateTo({startAt: {y: calculateOffset()}}, false)
|
|
|
|
})
|
|
|
|
//}
|
|
|
|
|
|
|
|
// for (var i = 0; i < sections.length; i++) {
|
|
|
|
// new ScrollMagic.Scene({
|
|
|
|
// triggerElement: sections[i]
|
|
|
|
// })
|
|
|
|
// .setClassToggle(sections[i], "appear")
|
|
|
|
// .addIndicators({name: "1 - add a class"}) // add indicators (requires plugin)
|
|
|
|
// .addTo(controllerAnimations);
|
|
|
|
// }
|