Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div id="content">
  <section class="blue"><span>青背景固定</span></section>
  <section class="yellow"><span>左から黄色背景</span></section>
  <section class="red"><span>右から赤背景</span></section>
</div><!-- /#content -->
              
            
!

CSS

              
                .blue,
.yellow,
.red {
  height: 500px;
  text-align: center;
  line-height: 500px;
  position: relative;
  font-size: 30px;
}

span {
  position: relative;
}

.blue {
  background: blue; 
}

.yellow::before{
  content: '';
  display: block;
  position: absolute;
  width: 100%;
  height: 100%;
  background: yellow;
  transition: 0.5s;
  transform-origin: left top;
  transform: scale(0, 1);
}

.red::before{
  content: '';
  display: block;
  position: absolute;
  width: 100%;
  height: 100%;
  background: red;
  transition: 0.5s;
  transform-origin: right top;
  transform: scale(0, 1);
}

.fade::before {
  transform: scale(1, 1);
}
              
            
!

JS

              
                $(function(){
  $(window).scroll(function (){
    $('.yellow, .red').each(function(){
      
      //要素の位置の取得
      var target = $(this).offset().top;
      
      //スクロール量を取得
      var scroll = $(window).scrollTop();
      
      //ウィンドウの高さを取得
      var windowHeight = $(window).height();
      
      //目的の要素が画面内に少し入ったらクラスを付与する
      if (scroll > target - windowHeight + 200){
          $(this).addClass('fade');
      }
    });
  });
});
              
            
!
999px

Console