Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <header role="banner">
  <nav class="anchor-nav" role="navigation">
    <a href="#section-1" id="anchor1">Section 1</a>
    <a href="#section-2" id="anchor2">Section 2</a>
    <a href="#section-3" id="anchor3">Section 3</a>
    <a href="#section-4" id="anchor4">Section 4</a>
  </nav>
</header>

<main class="full-screen" role="main">
  
  <section class="full-screen blue" id="section-1">
    <p>scroll X to view all the section</p>
     <img  class="title" src="https://daks2k3a4ib2z.cloudfront.net/597b56c58d2f010001d8bedb/59b81aa33e0c400001eeb8dc_170909_Muuaaa-Arsenal_Alcapurria-Quema_Coasters.png" alt="">
  </section>

  <section class="full-screen " id="section-2">
    <div id="overlay">
      <p>Section 2</p>

      <div class="animated-items">
        <a class="click-element"> <p>click me to scroll right</p></a>
      </div>
      </div>
    
  </section>

  <section class="full-screen " id="section-3">
    <div>
      <p>Section 3</p>
    </div>
  </section>

  <section class="full-screen " id="section-4">
    <div>
      <p>Section 4</p>
    </div>
  </section>
</main>
              
            
!

CSS

              
                /*
	Demo Styles: NOT REQUIRED
*/
html,
body {
  margin: 0;
  height: 100%
}
a {
  color: white;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}
a.active {
  color: #000;
  text-decoration: underline;
}

h1,
p {
  margin: 0;
  padding: 0;
}

header {
  position: fixed;
  top: 10px;
  left: 10px;
}
main{
  display: flex;
  flex-wrap: wrap; 
  height: 100%;
  width:calc(1280px *4 );
}
section {
  width:100%;
  max-width: 1280px;
  height: 100%;
  margin:auto; 
  position: relative;
  overflow:hidden;
}
 
.title{
  width:  750px;
  height: 502px;
  position: relative;
  z-index: 2; 
  border:2px solid orange;
  box-shadow: -23px 25px 54px 2px rgba(0, 0, 0, 0.24);
}
.animated-items{
  width:  750px;
  height: 502px;
  position: relative;
  z-index: 2; 
  border:2px solid orange;
  box-shadow: -23px 25px 54px 2px rgba(0, 0, 0, 0.24);
  opacity:0.7;
  display:block;
  background:url('http://accountbased.co.uk/SAP/00684/john-deere/images/img1.jpg'); 
  display: flex;
  justify-content:center;
 
}

.click-element{
  
  border:1px solid red;
  background:black;
  color:white;
  position: absolute;
  top:50%;
  padding:50px;
}

.blue {
	background-color: #3883d8;
}
.red {
	background-color: #cf3535;
}
.orange {
	background-color: #ea6300;
}

.darkblue #section-2, .click-element.active {
	background-color: #000080;
}
              
            
!

JS

              
                console.clear();

// Init controller
var controller = new ScrollMagic.Controller({
  globalSceneOptions: {
    duration: $("section").height(),
    triggerHook: 0.025,
    reverse: true
  },
  vertical: false
});

var scenes = {
  scene1: {
    "section-1": "anchor1"
  },
  scene2: {
    "section-2": "anchor2"
  },
  scene3: {
    "section-3": "anchor3"
  },
  scene4: {
    "section-4": "anchor4"
  }
};

for (var key in scenes) {
  // skip loop if the property is from prototype
  if (!scenes.hasOwnProperty(key)) continue;

  var obj = scenes[key];

  var scene = new ScrollMagic.Scene({
    triggerElement: "#section-1",
    duration: 200,
    triggerHook: "onLeave"
  }).addTo(controller);

  for (var prop in obj) {
    // skip loop if the property is from prototype
    if (!obj.hasOwnProperty(prop)) continue;

    new ScrollMagic.Scene({ triggerElement: "#" + prop })
      .setClassToggle("#" + obj[prop], "active")
      .addTo(controller);

    var tween = TweenMax.fromTo(
      "#section-1 .title",
      1,
      { xPercent: 25, scale: 0.6 },
      { xPercent: 75, x: 0, scale: 1 }
    );
    new ScrollMagic.Scene({
      triggerElement: "#section-1",
      duration: $("#section-1").outerWidth(true)
    })
      .setTween(tween)
      .addTo(controller)
      .tweenChanges(false);

    new ScrollMagic.Scene({
      triggerElement: "#section-1",
      duration: $("#section-1").outerWidth(true)
    })
      .on("enter", function() {
        $("#anchor1").addClass("selected");
        $("#section-1").addClass("animated fadeInUp");
      })
      .on("leave", function() {
        $("#anchor1").removeClass("selected");
        $("#section-1").removeClass("animated fadeInUp");
      })
      .addTo(controller);

    //--------------
    //SECTION-2 -- IMAGE SHOULD GO TO CENTER ON SECTION 2
    //--------------
    var tween = TweenMax.fromTo(
      "#section-2 .animated-items",
      1,
      { xPercent: -100 },
      { xPercent: 0, x: 0 }
    );
    new ScrollMagic.Scene({
      triggerElement: "#section-2",
      offset: -750,
      duration: $("#section-2").outerWidth(true)
    })
      .setTween(tween)
      .addTo(controller)
      .tweenChanges(false);

    new ScrollMagic.Scene({
      triggerElement: "#section-2",
      duration: $("#section-2").outerWidth(true)
    })
      .on("enter", function() {
        $("#anchor2").addClass("selected");
        $("#section-2").addClass("animated slideIn");
      })
      .on("leave", function() {
        $("#anchor2").removeClass("selected");
        $("#section-2").removeClass("animated slideIn");
      })
      .addTo(controller)
      .tweenChanges(false);

    
    
    
    
    
    
    //CLICK EVENT ON SECTION 2, AND WHEN SCROLLING BACK TO SECTION 1 IT SHOULD REVERT ALL

    var tween1 = new TimelineMax();
    tween1.to(".click-element", 0.3, {
      x: 0      
    }, 0) 

    $(".click-element").on("click", function(e) {
      tween1.play();
      
      TweenMax.to('#section-2', 0.3,{
      className: "+=darkblue"
    }, 0)
    });
 
    var scene1 = new ScrollMagic.Scene({
      triggerElement: "#section-2",
      offset: 50
    })
    .on("leave", function() {
      
    })
      .setClassToggle("body", "darkbluess")
      .setTween(tween1)
      .addTo(controller);

    scene1.addIndicators();
  }
}

// Change behaviour of controller
// to animate scroll instead of jump
controller.scrollTo(function(target) {
  TweenMax.to(window, 0.5, {
    scrollTo: {
      x: target,
      autoKill: true // Allow scroll position to change outside itself
    },
    ease: Cubic.easeInOut
  });
});

//  Bind scroll to anchor links using Vanilla JavaScript
var anchor_nav = document.querySelector(".anchor-nav");

anchor_nav.addEventListener("click", function(e) {
  var target = e.target,
    id = target.getAttribute("href");

  if (id !== null && id.length > 0) {
    e.preventDefault();
    controller.scrollTo(id);

    if (window.history && window.history.pushState) {
      history.pushState("", document.title, id);
    }
  }
});

window.addEventListener("wheel", onWheel);

function onWheel(event) {
  event.preventDefault();

  var normalized;
  var delta = event.wheelDelta;
  var scroll =
    (window.pageXOffset || document.scrollLeft) - (document.clientLeft || 0) ||
    0;

  if (delta) {
    normalized = delta % 120 == 0 ? delta / 120 : delta / 12;
  } else {
    delta = event.deltaY || event.detail || 0;
    normalized = -(delta % 3 ? delta * 10 : delta / 3);
  }

  normalized *= -1;

  TweenLite.to(window, 0.4, { scrollTo: { x: scroll + 200 * normalized } });
}

              
            
!
999px

Console