Search code examples
jqueryhtmlcssparallaxscrollmagic

Scroll Magic Parallax Problems


I'm just trying to create a basic 2 layer parallax effect with scrollmagic on my index page that has a gigantic image and content below it. I looked the the documentation and source code several times but it doesn't seem to work and I don't know what I'm missing:

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);

Solution

  • EDIT after edit of original post:

    I don't see TweenMax.js and animation.gsap.js referenced in your code - or is that somehow included in the other scripts?


    Another addition after second comment:

    TweenMax.js can be referenced like this

    <script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js"></script>
    

    animation.gsap.js like this:

    <script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.0/plugins/CSSPlugin.min.js"></script>
    

    but you should also find it in the "plugins" folder of your "scrollmagic" folder.