Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="main_content">
  <div class="fake_content one">
    <h2>Fake content</h2>
  </div>
  <div class="real_content">
    <div class="media_content">
      <div class="big_media">
        <img src="http://via.placeholder.com/1000x633" alt="big media">
      </div>
      <div class="smalls_media">
        <div class="square">
          <img src="http://via.placeholder.com/400x400" alt="square">
        </div>
        <div class="square">
          <img src="http://via.placeholder.com/400x400" alt="square">
        </div>
      </div>
      <span class="title_media back">Motion</span>
      <span class="title_media front">Developement</span>
    </div>
  </div>
  <div class="fake_content two">
    <h2>Fake content</h2>
  </div>
</div>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Open+Sans:300,400,700,800)

$primary: #E35205
$black: #000000
$white: #FFFFFF

img
  box-sizing: border-box
  border: 2px solid $primary

body
  margin: 0
  padding: 0

.main_content
  width: 100%
  margin: 0 auto
  font-family: 'Open sans', sans-serif
  
.fake_content
  display: flex
  justify-content: center
  align-items: center
  width: 100%
  background-color: rgba($primary, 0.8)
  
  &.one
    height: 800px
    
  &.two
    height: 1200px
    
  h2
    font-size: 80px
    line-height: 80px
    text-transform: uppercase
    font-weight: 800
    color: $white
    
.real_content
  width: 100%
  padding: 100px 100px 140px 100px //100 + 40px from transform
  box-sizing: border-box
  
.media_content
  position: relative
  display: flex
  align-items: flex-end
  
.title_media
  position: absolute
  display: block
  font-size: 150px
  line-height: 150px
  letter-spacing: -10px
  text-transform: uppercase
  font-weight: 800
  color: $black
  margin: 0
  left: 50%
  will-change: transform //IE like this
  
.front
  //top: 20px
  top: 260px

.back
  top: 120px
  //top: -100px
  //z-index: -1

.big_media
  //width: 60%
  img
    display: block
    max-width: 100%
    height: auto
  
.smalls_media
  width: 40%
  display: flex //Take care of flex in flex compatibility
  transform: translate(-100px, 40px)
  
  .square
    align-self: flex-end
    margin: 0 50px 0 0
    img
      display: block
      max-width: 100%
      height: auto
            
          
!
            
              $(document).ready(function($){
  
  //set DOM variables
  var $realContent = $('.real_content'),
      $titleFrontMedia = $('.title_media.front'),
      $titleBackMedia = $('.title_media.back');
  
  //set scrolling variables
  var scrollDelta = 2,
      scrollOffset = -1000;
  
  //set offset variables
  var offsetTopRealContent = $realContent.offset().top,
      realContentHeight = $realContent.outerHeight(),
      offsetBottomRealContent = offsetTopRealContent + realContentHeight;
  
  $(window).on('scroll', function(){
    var currentTop = $(window).scrollTop();
    
    if (currentTop >= (offsetTopRealContent + scrollOffset) && currentTop <= offsetBottomRealContent){
      // requestAnimationFrame
      titleAnimation(currentTop);
    }
    
  });
  
  function titleAnimation(currentTop){
    
    var transformNegativeTranslate = "translate(-" + currentTop/scrollDelta + "px, 0)",
        transformNegativeFasterTranslate = "translate(-" + currentTop/(scrollDelta+2) + "px, 0)";
        //transformPositiveTranslate = "translate(+" + currentTop/scrollDelta + "px, 0)";
     
    $titleFrontMedia.css({"-moz-transform" : transformNegativeFasterTranslate, "-webkit-transform" : transformNegativeFasterTranslate});
    $titleBackMedia.css({"-moz-transform" : transformNegativeTranslate, "-webkit-transform" : transformNegativeTranslate});
   
  }
  
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console