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 class="mv">
      <div class="item js-tg"></div>
    </div>
              
            
!

CSS

              
                * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
        font-family: 游ゴシック体, 'Yu Gothic', YuGothic, 'ヒラギノ角ゴシック Pro', 'Hiragino Kaku Gothic Pro', メイリオ, Meiryo, Osaka, 'MS Pゴシック', 'MS PGothic', sans-serif;
      }
      body, html {
        width: 100%;
        height: 100%;
      }
      .mv {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
      }

      .mv .item {
        width: 20vw;
        height: 20vw;
        border-radius: 50%;
        overflow: hidden;

        -webkit-mask-image: radial-gradient(
          transparent 0%,
          transparent 30%,
          #000 30%,
          #000 100%
        );
      }
              
            
!

JS

              
                
// 動かす要素
tg = $('.js-tg');

// アニメーションで使う
param = {
  rate:0,
  cnt:0,
  rotate:0,
  offset:0 // 隠し味的な
};

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

  TweenMax.to(param, 2, {
    rate:1,
    repeat:-1,
    yoyo:false,
    ease:Power3.easeInOut,
    onRepeat: function() {
      param.cnt++
    }
  })

  update();
}

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

  var per = (param.rate * 100) + '%'
  var color1;
  var color2;
  var bgColor;
  if(param.cnt % 2 == 0) {
    color1 = chroma.mix(0x000000, 0xffffff, param.rate).css();
    color2 = 'transparent';
    bgColor = chroma.mix(0xffffff, 0x000000, param.rate).css();
  } else {
    color1 = 'transparent';
    color2 = chroma.mix(0xffffff, 0x000000, param.rate).css();
    bgColor = chroma.mix(0x000000, 0xffffff, param.rate).css();
  }

  param.rotate = param.rate * 360 + param.offset;
  param.offset += 1;

  // conic-gradient()部分
  var grad = 'conic-gradient(';
  grad += 'from ' + param.rotate + 'deg, ';
  grad += color1 + ' 0,';
  grad += color1 + ' ' + per + ',';
  grad += color2 + ' ' + per + ',';
  grad += color2 + '';
  grad += ')';

  tg.css({
    backgroundImage:grad
  });

  $('body').css({
    backgroundColor:bgColor
  });

  window.requestAnimationFrame(update);
}





// ########################################
// ユーティリティ系 ↓
// ########################################

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

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

// ----------------------------------------
// minからmaxまでランダム 半分の確率で-をつける
// ----------------------------------------
function random2(min, max) {
  var val = Math.random() * (max - min) + min;
  if(Math.random() > 0.5) {
    val *= -1;
  }
  return val;
}

// ----------------------------------------
// -valからvalまでランダム
// ----------------------------------------
function range(val) {
  return random(-val, val);
}

// ----------------------------------------
// 配列の中ランダム
// ----------------------------------------
function randomArr(arr) {
  return arr[randomInt(0, arr.length - 1)]
}

// 1 / rangeの確率でtrueを取得
// -----------------------------------
// @range : 2以上の分母(int)
// return : true or false(boolean)
// -----------------------------------
function hit(range) {
  return (randomInt(0, range - 1) == 0)
}

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

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


// ----------------------------------------
// 範囲変換
// @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