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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console