cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <body>
  <div class="mv">
      <div class="dot js-tg"><div class="inner colorA"></div></div>
      <div class="dot js-move"><div class="inner colorB"></div></div>
    </div>
</body>
            
          
!
            
              * {
        box-sizing: border-box;
      }
      body, html {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
      }
      .mv {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        background-color: #f4f1cc;
      }
      .dot {
        position: absolute;
        top: 0;
        left: 0;
      }
      .dot .inner {
        position: absolute;
        top: -50px;
        left: -50px;
        width: 100px;
        height: 100px;
        border-radius: 50px;
      }
      .colorA {
        border: 2px solid #549067;
        opacity: 0;
      }
      .colorB {
        background-color: #d967b5;
      }
            
          
!
            
              
// 最終目標値までの進捗度
rate = 0;

// 最終目標値
clickPos = {x:0, y:0};

// 現在値
movePos = {x:0, y:0};

init();


// 初期設定
function init() {

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

  // 最初はランダム
  clickPos.x = random(0, sw);
  clickPos.y = random(0, sh);

  // クリックしたところを最終目標値に
  $(window).on('click', _eClick);

}


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

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

  // イージングかける
  ease = 0.07;

  // 進捗度 1へ近づける
  rate += (1 - rate) * ease;

  // だいたい1に近づいたら目標値変更
  if(Math.abs(1 - rate) < 0.005) {
    _eClick();
  }

  // 寄り道ターゲット
  tg = $('.js-tg');

  // 画面真ん中へ寄り道
  tgX = sw * 0.5;
  tgY = sh * 0.5;

  // 動かすやつ
  move = $('.js-move');

  // 進捗度を使って、寄り道しつつ最終的にクリックした位置へ行くように
  moveX = (tgX * (1 - rate)) + (clickPos.x * rate);
  moveY = (tgY * (1 - rate)) + (clickPos.y * rate);
  movePos.x += (moveX - movePos.x) * ease;
  movePos.y += (moveY - movePos.y) * ease;

  // DOM更新
  TweenMax.set(move, {
    x:movePos.x,
    y:movePos.y
  });
  TweenMax.set(tg, {
    x:tgX,
    y:tgY
  });

  window.requestAnimationFrame(update);
}

// ----------------------------------------
// イベント 画面クリック
// ----------------------------------------
function _eClick(e) {

  rate = 0;

  if(e == null) {
    clickPos.x = random(0, window.innerWidth);
    clickPos.y = random(0, window.innerHeight);
  } else {
    clickPos.x = e.clientX;
    clickPos.y = e.clientY;
  }

}




// ----------------------------------------
// 度からラジアンに変換
// @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;
}

            
          
!
999px
Loading ..................

Console