Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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.content.js-Character_Change
  div.character.js-Character_Target
    div.egg
      img(src="https://dl.dropbox.com/s/k8c2ohkz66sykbo/egg.png?dl=0" alt="卵")
    div.chick
      img(src="https://dl.dropbox.com/s/9tl5urilcpo60mt/chick.png?dl=0" alt="ひよこ")
  div.btn.js-Character_Switcher クリック!!
  div.canvas.js-Character_Canvas
              
            
!

CSS

              
                .content{
  padding: 40px 0 0;
  position: relative;
  z-index: 1;
  .character{
    width: 200px;
    height: 200px;
    margin: 0 auto;
    position: relative;
    > div{
      margin: 0 auto;
      position: absolute;
      left: 0;
      right: 0;
      &.off{
        animation: scale-down .1s ease-in forwards;
      }
      &.on{
        animation: scale-easeOutElastic .75s ease-in forwards;
      }
      img{
        width: 100%;
        height: auto;
      }
    }
    .egg{
      width: 120px;
      top: 40px;
    }
    .chick{
      width: 200px;
      top: 0;
      transform: scale(0);
    }
  }
  .btn{
    width: 200px;
    height: 50px;
    margin: 40px auto 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffe384;
    border-radius: 25px;
    box-shadow: 0 4px 0 0 #fcbe03;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    color: #333;
    &:hover{
      transform: translateY(4px);
      box-shadow: none;
    }
  }
  .canvas{
    width: 500px;
    height: 500px;
    position: absolute;
    top: -90px;
    left: 50%;
    transform: translateX(-50%);
    z-index: -1;
  }
}
@keyframes scale-down {
	0% { transform: scale(1); }
	100% { transform: scale(0); }
}
@keyframes scale-easeOutElastic {
	0% { transform: scale(0); }
	16% { transform: scale(1.1); }
	28% { transform: scale(.9); }
	44% { transform: scale(1.025); }
	59% { transform: scale(.975); }
	73% { transform: scale(1.0125); }
	88% { transform: scale(1); }
	100% { transform: scale(1); }
}
              
            
!

JS

              
                $('.js-Character_Change').each(function(){
  const $this = $(this);
  const $target = $this.children('.js-Character_Target');
  const $switcher = $this.children('.js-Character_Switcher');
  const $canvas = $this.children('.js-Character_Canvas');

  let canvasWidth = $canvas.innerWidth();
  let canvasHeight = $canvas.innerHeight();

  // アプリケーションの作成
  const app = new PIXI.Application(canvasWidth, canvasHeight, {transparent : true});
  $canvas.append(app.view);

  // コンテナの作成
  let container = new PIXI.Container();
  // ステージに反映
  app.stage.addChild(container);
  container.x = 0;
  container.y = 0;

  // 表示をするパーティクルの数
  let totalParticle = 50;

  // 画像配列
  let images = ['https://dl.dropbox.com/s/eejj0fryiojjcfw/star.png?dl=0']

  // クリック処理
  let index = 0;
  $switcher.on('click',function(){

    // 切り替え処理
    const targetLength = $target.children().length - 1;
    index+=1;
    if(index > targetLength){
      index = 0;
    }
    $target.children('div').addClass('off').removeClass('on');
    $target.children('div').eq(index).removeClass('off').addClass('on');

    // パーティクル用の配列
    const particles = [];

    // totalParticle回数分ループ
    for (let i = 0; i < totalParticle; i++) {

      // パーティクルの画像設定
      let n = Math.floor(Math.random() * images.length);
      const particle = PIXI.Sprite.from(images[n]);

      // パーティクルの中心をきめる
      particle.anchor.set(0.5);

      // 透明度
      particle.alpha = 1;

      // サイズをランダムにきめる
      const max = app.screen.width * 0.000166666666667;
      const size = Math.random() * max;
      particle.scale.set(size);

      // パーティクルの位置をcanvasの中心に
      particle.x = app.screen.width / 2;
      particle.y = app.screen.height / 2;

      // 速度と向き
      particle.vx = app.screen.width * 0.02 * (Math.random() - 0.5); // 0~1 - .5 = -.5 ~ .5;
      particle.vy = app.screen.width * 0.02 * (Math.random() - 0.5);

      // 寿命
      particle.life = 100;

      // 生成されたパーティクルの配列をpushして簡単にアクセスできるようにします
      particles.push(particle);

      // コンテナに反映
      container.addChild(particle);

    }

    // アニメーションフレーム毎の処理を指定
    app.ticker.add(function() {

      // 画像を繰り返し処理して位置を更新する
      for (let i = 0; i < particles.length; i++) {
        //配列を代入
        const particle = particles[i];

        // 透明度
        particle.alpha -= 0.01;
        
        // サイズ変化
        particle.scale.x *= .99;
        particle.scale.y *= .99;

        // 回転
        particle.rotation += 0.1;

        // 寿命
        particle.life -= 1;

        // 摩擦
        particle.vx *= .98;
        particle.vy *= .98;

        // 速度を位置に足していく
        particle.x += particle.vx;
        particle.y += particle.vy;

        if (particle.life <= 0) {
          // コンテナから削除
          container.removeChild(particle);
          // 配列からも削除(i番目から1個削除)
          particles.splice(i, 1);
        }
      }
    });
  });
});
              
            
!
999px

Console