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-tg"><div class="inner colorB"></div></div>
      <div class="dot js-tg"><div class="inner colorC"></div></div>
      <div class="dot js-tg"><div class="inner colorA"></div></div>
      <div class="dot js-tg"><div class="inner colorB"></div></div>
      <div class="dot js-tg"><div class="inner colorC"></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 {
        background-color: #dd9588;
      }
      .colorB {
        background-color: #68bc9b;
      }
      .colorC {
        background-color: #9b99be;
      }
            
          
!
            
              
param = [];

init();

// 初期設定
function init() {

  $('.js-tg').each(function(i,e) {

    obj = {
      rate:0,            // 最終目標値までの進捗度
      posTg2:{x:0, y:0}, // 最終目標位置
      posTg1:{x:0, y:0}, // 寄り道位置
      posNow:{x:0, y:0}, // 現在位置
      el:$(e),
      scale:1,
      isStart:false
    }
    reset(obj, i * 0.3);
    param.push(obj);

  });

}


// リセット
function reset(obj, delay) {

  sw = window.innerWidth
  sh = window.innerHeight

  obj.rate = 0;

  obj.posNow.x = random(sw * 0.25, sw * 0.75);
  obj.posNow.y = sh * 1.25;

  // 最終目標位置 画面外へ
  obj.posTg2.x = sw * 0.5;
  obj.posTg2.y = -sh * 0.2;

  // 寄り道
  range = 1;
  obj.posTg1.x = obj.posNow.x + random(-sw * range, sw * range);
  obj.posTg1.y = random(sh * 0.4, sh * 0.6);

  // スケールのランダムに
  obj.scale = random(0.5, 1);

  // rate値をアニメーション
  TweenMax.killTweensOf(obj);
  TweenMax.to(obj, 1, {
    rate:1,
    ease:Power3.easeOut,
    delay:delay
  })

}


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

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

  len = param.length;
  for(var i = 0; i < len; i++) {

    obj = param[i];

    if(obj.rate > 0) {
      // 進捗度を使って、寄り道しつつ最終的にクリックした位置へ行くように
      tgX = (obj.posTg1.x * (1 - obj.rate)) + (obj.posTg2.x * obj.rate);
      tgY = (obj.posTg1.y * (1 - obj.rate)) + (obj.posTg2.y * obj.rate);
      obj.posNow.x += (tgX - obj.posNow.x) * ease;
      obj.posNow.y += (tgY - obj.posNow.y) * ease;
    }

    // DOM更新
    TweenMax.set(obj.el, {
      x:obj.posNow.x,
      y:obj.posNow.y,
      scale:obj.scale
    });

    // だいたい1に近づいたら目標値変更
    if(Math.abs(1 - obj.rate) < 0.005) {
      reset(obj, random(0, 0.5));
    }
  }

  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;
}

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

Console