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

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.

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

              
                <!-- Static navbar -->
<nav class="navbar navbar-default navbar-static-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Project name</a>
    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="#contact">Contact</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li class="dropdown-header">Nav header</li>
            <li><a href="#">Separated link</a></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="../navbar/">Default</a></li>
        <li class="active"><a href="./">Static top <span class="sr-only">(current)</span></a></li>
        <li><a href="../navbar-fixed-top/">Fixed top</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</nav>
<main class="main-content">
  <section class="video-hero">
    <div class="container">
      <div class="video-hero__header js-video-header">
        <h2 style="margin:0;">Lorem ipsum dolor.</h2>
        <nav class="navbar navbar-default">
        <div class="container-fluid">
          <ul class="nav navbar-nav">
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </div><!--/.container-fluid -->
      </nav>
      </div>
      <div class="video-hero__video-container">
        <div class="video-hero__video-wrapper js-video">
          <iframe id="video-player" width="560" height="315" src="https://www.youtube.com/embed/kfVsfOSbJY0?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
        </div>
      </div>
    </div>
  </section>
  <section class="content">
    <div class="container">
      <div class="row">
        <div class="col-sm-8">
          <div class="content-module"></div>
          <div class="content-module"></div>
          <div class="content-module"></div>
          <div class="content-module"></div>
          <div class="content-module"></div>
        </div>
        <div class="col-sm-4">
          <div class="sidebar js-sidebar">
            <h2 style="margin:0;">Sidebar</h2>
          </div>
        </div>
      </div>
    </div>
  </section>
</main>
              
            
!

CSS

              
                .video-hero {
  
  &__header {
    background-color: #fff;
    z-index: 2;
    
    .navbar {
      margin: 0;
    }
  }
  
  &__video-container {
    // transform: translateZ(0);
  }

  &__video-container,
  &__video-wrapper {
    height: 0;
    padding-bottom: 56.25%;
    position: relative;
    width: 100%;
  }
  
  &__video-wrapper {
    z-index: 1;
    > iframe,
    > video,
    > object {
      position: absolute;
      top: 0;
      left: 0;
      height: 100%;
      width: 100%;
    }
  }
  
  
}

.content-module {
  background: #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 400px;
  margin-bottom: 25px;
  
  &::after {
    content: 'Some Content';
    font-size: 2em;
  }
}
              
            
!

JS

              
                var player
  , scrollMagic = {}
  , animationProps = {
    duration: .55,
    easing: Power1.easeOut
  }
  , videoLayout = {}
  , selectors = {
      sidebar: '.js-sidebar',
      videoHeader: '.js-video-header',
      video: '.js-video'
    }
  // set up jQuery references to everything in the selectors object.
  , $refs = Object.keys(selectors).reduce(function (obj, current) {
      obj[current] = $(selectors[current])
      return obj;
    }, {});

function init() {
  scrollMagic.controller = new ScrollMagic.Controller();
  scrollMagic.headerScene = new ScrollMagic.Scene({
    loglevel: 0,
    triggerElement: selectors.videoHeader, 
    triggerHook: 0
  })
    .setPin(selectors.videoHeader)
    .addTo(scrollMagic.controller);
}

// need to defer setting up video scene until video has loaded.
function setupVideoScene() {
  
  scrollMagic.videoScene = new ScrollMagic.Scene({
    loglevel: 0,
    offset: -($refs.videoHeader.outerHeight()),
    triggerElement: selectors.sidebar, 
    triggerHook: 0
  })
    .setPin(selectors.sidebar)
    .addTo(scrollMagic.controller);
  
  scrollMagic.videoScene.on('enter', function(event) {
    console.log('enter :: ', event);
    if (event.scrollDirection === 'FORWARD') {
      var videoOffset = $refs.video.parent().offset();
      var sidebarOffset = $refs.sidebar.offset();
      
      videoLayout.height = $refs.video.parent().outerHeight();
      videoLayout.width = $refs.video.parent().width();
      videoLayout.top = videoOffset.top;
      videoLayout.left = videoOffset.left;
      
      TweenMax.fromTo(
        selectors.video,
        animationProps.duration,
        {
          height: videoLayout.height,
          width: videoLayout.width,
          top: videoLayout.top,
          left: videoLayout.left,
          y: '-100%' 
        },
        {
          ease: animationProps.easing,
          height: $refs.sidebar.width() * .5625,
          width: $refs.sidebar.width(),
          top: $refs.videoHeader.outerHeight(),
          left: sidebarOffset.left,
          y: '0%',
          padding: 0,
          position: 'fixed'
        }
      );
    }
  });
  
  scrollMagic.videoScene.on('leave', function(event) {
    console.log('leave :: ', event);
    
    var videoOffset = $refs.video.offset();
    var videoParentOffset = $refs.video.parent().offset();
    
    if (event.scrollDirection === 'REVERSE') {
      TweenMax.fromTo(
        selectors.video, 
        animationProps.duration,
        {
          height: $refs.video.height(),
          width: $refs.video.width(),
          top: videoOffset.top - videoParentOffset.top,
          left: videoOffset.left - videoParentOffset.left,
          y: '0%',
          position: 'absolute'
        },
        {
          ease: animationProps.easing,
          height: videoLayout.height,
          width: videoLayout.width,
          top: 0,
          left: 0,
          paddingBottom: '56.25%'
        }
      );
    }
  });
}

function onYouTubeIframeAPIReady() {
  player = new YT.Player('video-player', {
    events: {
      onReady: onPlayerReady
    }
  });
}

function onPlayerReady(event) {
  console.log('onPlayerReady');
  setupVideoScene();
}

//
// Init
// --------------------------------------------------
init();
              
            
!
999px

Console