I have been trying to implement a basic 2 layer parallax effect using ScrollMagic on my index page. The layout consists of a large image with content below it, but I am facing some challenges. Despite going through the documentation and source code multiple times, I can't seem to get it to work. Here is a snippet of the code I am working with:
HTML:
<div class="row zero-padding parallaxParent" id="parallax1">
<div class="col-xs-12 zero-padding index--background" style="background-image: url('{{ backgroundimage.picture.url }}')">
<h1>MACRO FOODS</h1>
<h2>Healthy made easy</h2>
</div>
</div>
<div class="row zero-padding">
<div class="col-xs-12 index--title">
<p> What is Macro Foods?</p>
</div>
</div>
<div class="row zero-padding index--blockwrap">
<div class="col-xs-12 col-md-8">
<p class="index--body">{{ whatismacrofoods.text }}
</div>
<div class="col-xs-12 col-md-4">
<img class="index--image" src="{{ imagesindex1.picture.url }}">
</div>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/ScrollMagic.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/plugins/debug.addIndicators.min.js"></script>
<!--Custom-->
<script src="{% static 'scripts/main.js' %}"></script>
<script src="{% static 'scripts/parallax.js' %}"></script>
CSS:
.parallaxParent {
height: 100vh;
overflow: hidden;
}
.parrallaxParent > * {
height: 200%;
position: relative;
top: -100%;
}
Parallax.js:
//Parallax Scrollmagic
var controller = new ScrollMagic.Controller({globalSceneOptions: {triggerHook: "onEnter", duration: "200%"}});
new ScrollMagic.Scene({triggerElement: "#parallax1", duration: "120%"})
.setTween("#parallax1 > div", {y: "80%", ease: Linear.easeNone})
.addIndicators()
.addTo(controller);
new ScrollMagic.Scene({triggerElement: "#parallax2"})
.setTween("#parallax2 > div", {y: "80%", ease: Linear.easeNone})
.addIndicators()
.addTo(controller);
new ScrollMagic.Scene({triggerElement: "#parallax3"})
.setTween("#parallax3 > div", {y: "80%", ease: Linear.easeNone})
.addIndicators()
.addTo(controller);