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

              
                
<div class="slides-container">
  
	<div class="slide slide01 active" id="slide-1">
		
    <div class="wrapper mouse">
      <img src="https://unsplash.it/300/500?image=766"/>
    </div>
    <h1>SCROLL ...</h1>
	</div>

	<div class="slide slide02" id="slide-2">
		<h1>TWO</h1>
    <div class="wrapper mouse">
      <img src="https://unsplash.it/1000/500?image=766"/>
    </div>
	</div>

  <div class="slide slide03" id="slide-3">
    <div class="wrapper centered">
     
    </div>
    <h1>THREE</h1>
  </div>

</div>
    

              
            
!

CSS

              
                body, div, p {
  margin: 0;
  padding: 0;
  font-family:sans-serif;
  background-color:grey;
}


.slides-container {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 10;
}

.slide {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
h1 {
  position: absolute;
  top: 5%;
  left: 5%;
  font-weight: 800;
  font-size: 40px;
  line-height: 34px;
  color: #484848;
  margin: 0;
}

.mouse{
  cursor: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/174563/kreis.svg), pointer;
}
.slide01 .wrapper{
  position: relative;
  top: 5%;
  left: calc(90% - 200px);
  width: 200px;
  height: 69vh;
  overflow: hidden;
}
.slide01 img{
  position: relative;
  width: 50vh;
}

.slide02 .wrapper{
  position: relative;
  top: 30%;
  width: 100%;
  height: 60vh;
  overflow: hidden;
}
.slide02 img{
  position: relative;
  width: 100%;
}

.slide03 .wrapper{
  position: relative;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background-image: url(https://unsplash.it/1200/800?image=889);
  background-size: cover;
}


              
            
!

JS

              
                
//Forked from [Chrysto](http://codepen.io/bassta/)'s 

console.clear();

TweenMax.set(".centered", {autoAlpha: 1, xPercent:-50, yPercent:-50, force3D:true});	


//References to DOM elements
var $window = $(window);
var $document = $(document);


var $slidesContainer = $(".slides-container");
var $allSlides = $(".slide");
var $currentSlide = $allSlides.first();

//defaultEase for all animations - except ...
TweenLite.defaultEase = Linear.easeNone;

//Animating flag - is our app animating
var isAnimating = false;

//The height of the window
var pageHeight = $window.innerHeight();

//Key codes for up and down arrows on keyboard. We'll be using this to navigate change slides using the keyboard
var keyCodes = {
  UP  : 38,
  DOWN: 40
};

// individual animations per slide
var currentIndex = 0;

const el = document.querySelectorAll(".slide");
const slides = [].slice.call(el); 
slidesNo = slides.length;
let animations = [];


// create animation timelines
for(let [i] of slides.entries()) {
  animations[i] = new TimelineMax({});
}

animations[0]
  .from('.slide01 .wrapper',1,{width:100},0)
  .reverse();

animations[1]
  .from('.slide02 .wrapper',1,{height:'15%'},0)
  .reverse();

animations[2]
  .from('.slide03 .wrapper',1,{width:'50%', height:'50vh'},0)
  .reverse();    




//Going to the first slide

animations[currentIndex].reversed(false);

/*  Adding event listeners  */

$window.on("resize", onResize).resize();
$window.on("mousewheel DOMMouseScroll", onMouseWheel);

/* When user scrolls with the mouse, we have to change slides */
function onMouseWheel(event){
  //Normalize event wheel delta
  var delta = event.originalEvent.wheelDelta / 30 || -event.originalEvent.detail;

  //If the user scrolled up, it goes to previous slide, otherwise - to next slide
  if(delta < -1){
    goToNextSlide();
  }
  else if(delta > 1){
    goToPrevSlide();
  }
  event.preventDefault();
}

/*  If there's a previous / next slide, slide to it */

function goToPrevSlide() {
  if($currentSlide.prev().length) {
    goToSlide($currentSlide.prev());
  }
}

function goToNextSlide() {
  if($currentSlide.next().length){ 
    goToSlide($currentSlide.next());
  }
}


  /*  Actual transition between slides */

  function goToSlide($slide){
    //If the slides are not changing and there's such a slide
    if(!isAnimating && $slide.length){
      //setting animating flag to true
      isAnimating = true;
      $currentSlide = $slide;

      NextSlide = $currentSlide.next()      

      var currentTime = animations[currentIndex].time();
      
      function end(){
        animations[currentIndex].timeScale(4).reversed(true);
        currentTime = animations[currentIndex].time();
      }
      
      console.log(currentTime); // expected 0.25 ???
      
      //Sliding to current slide
      var action = new TimelineMax({onStart: end})
      .to($slidesContainer, 1, {scrollTo: {y: pageHeight * $currentSlide.index() }, ease: Power2.easeOut, onComplete: onSlideChangeEnd, onCompleteScope: this},currentTime);

    // currentTime/4 + 0.2

    }
  }

  /*
	*   Once the sliding is finished, we need to restore "isAnimating" flag.
	*   You can also do other things in this function, such as changing page title
	* */
  function onSlideChangeEnd() {
    isAnimating = false;

    // Change the index
    currentIndex = $currentSlide.index();

    // Play the timeline for the current slide
    animations[currentIndex].timeScale(1).reversed(false);
  }

  /*
	*   When user resize it's browser we need to know the new height, so we can properly align the current slide
	* */
  function onResize(event){

    //This will give us the new height of the window
    var newPageHeight = $window.innerHeight();

    /*
		*   If the new height is different from the old height ( the browser is resized vertically ), the slides are resized
		* */
    if(pageHeight !== newPageHeight){
      pageHeight = newPageHeight;

      //This can be done via CSS only, but fails into some old browsers, so I prefer to set height via JS
      TweenLite.set([$slidesContainer, $allSlides], {height: pageHeight + "px"});

      //The current slide should be always on the top
      TweenLite.set($slidesContainer, {scrollTo: {y: pageHeight * $currentSlide.index() }});
    }

  }

// =======================================

$(".mouse")
  .mousedown(function() {
  TweenLite.to('img',0.5,{scale:2})
})
  .mouseup(function() {
  TweenLite.to('img',0.5,{scale:1})
});
              
            
!
999px

Console