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

              
                <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

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

<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenLite.min.js"></script>

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

<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.0/utils/Draggable.min.js"></script>

<div class="landing-wrapper">
  <div class="landing-inner-content">
    <div class="slide one"></div>
    <div class="slide two"></div>
    <div class="slide three"></div>
    <div class="slide four"></div>
    <div class="slide five"></div>
  </div>
</div>
              
            
!

CSS

              
                * {
  box-sizing:content-box;
}

html{
  height:100%; /* allows body tag to take full height */
}

body {
  margin:0 30px;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #444;
  color:#FFF;
}


.landing-wrapper {
  width: 100vw;
  height: 100vh;
  margin:20px auto;
  padding:0;
  position: relative;
  overflow:hidden;
  border:1px solid #333;
  cursor:pointer;
}

.landing-inner-content {
  background-color: coral;
  width: 150vw;
  height: 500vh;
}

.slide {
  display: block;
  position: absolute;
  height: 200px;
  width: 200px;
  left: 50%;
  background: red;
}

.one {
  position: absolute;
  top: 75%;
}

.two {
  position: absolute;
  height: 300px;
  width: 500px;
  left: 20%;
  top: 20%;
  /*background: green;*/
   background: url('https://dl.dropboxusercontent.com/s/kb6os50nu3j31cv/aa.jpg?dl=0') no-repeat;
  background-size:contain;
}

.three {
  left: 75%;
  top: 40%;
  width: 400px;
  background: blue;
}

.four {
  background: green;
  left: 50%;
  top: 100px;
  width: 300px;
}

.five {
  background: pink;
  left: 50%;
  top: 400px;
  width: 500px;
  margin: 100px;
}
              
            
!

JS

              
                $(window).on("load", function() {
  
  var tween;
 
  // size of viewport with hidden overflow
  var $landingWrapper = $(".landing-wrapper");
  
  // wraps slides, larger than viewport; coral background for visualization 
  var $landingInnerContent = $(".landing-inner-content");
  
  
  // AUTO-SCROLL 
  var xMove, yMove; 
  
  var isHovered = false;
  
  // detect scroll direction
  $landingInnerContent.on("mousemove touchmove", function(e) {
  	xMove = "+=0", yMove = "+=0";
    if (e.clientX > $landingWrapper.width() / 2) {
      xMove = "+=500";
    } else {
      xMove = "-=500";
    }
    if (e.clientY > $landingWrapper.height() / 2) {
      yMove = "+=500";
    } else {
      yMove = "-=500";
    }
    
    // one tween per mouse call 
    if(!isHovered) {
      tween = TweenMax.to($landingWrapper, 2, {
        scrollTo: {
          x: xMove,
          y: yMove
        },
        ease: Power0.easeNone,
        overwrite:"all" // added by ZachSaucier from GreenSock forum to stop conflict with previous tweens
      });
    }
  });
  
  /* HELP NEEDED HERE - HOW TO IMPLEMENT? 
  
  when a div is hovered, using .three as an example, trying to make the tween 'pause'... this will be a slider on real website, and i need the user to be able to click through the slides without the mouse movement triggering the animation?
  */
  $(".three").on("mouseenter",function(){
    isHovered = true;
    tween.kill();
  }).on("mouseleave",function(){
    isHovered = false;
  });

});

// --------------------------
// code in question ends here 

/* PARALLAX EFFECTS - COMMENTED OUT FOR CLARITY

// retrieve container position relative to viewport
var rect = $('.landing-wrapper')[0].getBoundingClientRect();
// create mouse object to keep track of mouse coordinates
var mouse = {x: 0, y: 0, moved: false};

$(".landing-wrapper").mousemove(function(e) {
  // set moved property to true when the mouse moves 
  mouse.moved = true;
  // calculate mouse coordinates
  mouse.x = e.clientX - rect.left; // e = event 
  mouse.y = e.clientY - rect.top;
});
 
// ticker event will be called on every frame
TweenLite.ticker.addEventListener('tick', function(){
  // if mouse is moved call parallax function
  if (mouse.moved) {    
    // parallaxIt takes two parameters
    // first is the target element
    // Second is how much the element should move
    // Movement is relative to height and width of parent, in this case the container
    // insert all your parallax calls here
    // you can insert more parameters to change duration etc for each element
    parallaxIt(".two", 1, -75);
    parallaxIt(".one", 1, -100);
    parallaxIt(".three", 1, 100);
  }
  // set moved property to false on each frame so parallax function won't be called more than once
  mouse.moved = false;
});

//parallaxIt(".landing-wrapper", 1, 10);

// Simplest part, take mouse coordinates and container dimensions and animate elements
function parallaxIt(target, duration, movement) {
  TweenMax.to(target, duration, {
    x: (mouse.x - rect.width / 2) / rect.width * movement,
    y: (mouse.y - rect.height / 2) / rect.height * movement, ease:Sine.easeOut}); //SlowMo.ease});
  
}
*/

// Recaclulate container dimensions on resize and scroll

$(window).on('resize scroll', function(){
  rect = $('.landing-wrapper')[0].getBoundingClientRect();
})
              
            
!
999px

Console