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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <body>
<div class="mv">
      <div class="obj"></div>
    </div>
    <div class="attention"><p>SCROLL</p></div>
    <div class="dummy_height"></div>
</body>
              
            
!

CSS

              
                * {
        box-sizing: border-box;
      }
      body, html {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
      }
      .mv {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        background-color: #1b2920;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
      }
      .obj {
        width: 70%;
        height: 70%;
      }
      .dummy_height {
        position: absolute;
        top:5000px;
        width: 1px;
        height: 1px;
      }
      .attention {
        position: fixed;
        width: 100%;
        height: 100%;
        color: #FFF;
        font-weight: bold;
        font-size: 18px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-end;
        letter-spacing: 0.05em;
      }
              
            
!

JS

              
                

init();


// 初期設定
function init() {
}


// 毎フレーム実行
window.requestAnimationFrame(update);
function update() {

  // ステージサイズ
  var sw = window.innerWidth;
  var sh = window.innerHeight;

  // スクロール位置
  var scroll = $(window).scrollTop();

  // スクロール進捗率 0 ~ 1
  var scrollP = scroll / ($(document).height() - sh);

  // 下に行くにつれ色が変わる
  $('.mv > .obj').css({
    backgroundColor:chroma.mix(0x7fb6a2, 0xc13d23, scrollP).css()
  });

  window.requestAnimationFrame(update);
}








// ----------------------------------------
// 度からラジアンに変換
// @val : 度
// ----------------------------------------
function radian(val) {
  return val * Math.PI / 180;
}

// ----------------------------------------
// ラジアンから度に変換
// @val : ラジアン
// ----------------------------------------
function degree(val) {
  return val * 180 / Math.PI;
}

// ----------------------------------------
// minからmaxまでランダム
// ----------------------------------------
function random(min, max) {
  return Math.random() * (max - min) + min;
}

// ----------------------------------------
// 範囲変換
// @val     : 変換したい値
// @toMin   : 変換後の最小値
// @toMax   : 変換後の最大値
// @fromMin : 変換前の最小値
// @fromMax : 変換前の最大値
// ----------------------------------------
function map(val, toMin, toMax, fromMin, fromMax) {
  if(val <= fromMin) {
    return toMin;
  }
  if(val >= fromMax) {
    return toMax;
  }
  p = (toMax - toMin) / (fromMax - fromMin);
  return ((val - fromMin) * p) + toMin;
}

              
            
!
999px

Console