cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              <div id="content">
    <button id="btnstart">スタート</button>
    <button id="btnreset">リセット</button>
    <ul>
      <li>フレームごとに、桜のimgタグを生成する</li>
      <li>全ての桜についてcssプロパティ(位置、回転、サイズ、透過度)などを更新する。</li>
    </ul>
</div>
            
          
!
            
                      body{
            position: relative;
        }
        img{
            position: absolute;
        }
        #content{
            position: relative;
        }

            
          
!
            
              
    $(function(){
        var rand = function(min, max) {
            return Math.floor((Math.random() * (max - min + 1)) + min);
        };

        var img =[];
        img.push( $('<img src="https://raw.githubusercontent.com/tomothumb/css-jquery-pixi-AnimationDemo/master/img/sakura1.png" class="sakuraimg">') );
        img.push( $('<img src="https://raw.githubusercontent.com/tomothumb/css-jquery-pixi-AnimationDemo/master/img/sakura2.png" class="sakuraimg">') );

        //桜オブジェクト
        function SAKURA(){
            this.cntX = rand(0, 100);
            this.cntY = rand(0, 100);
            this.$ele = img[rand(0,1)].clone();
            this.init = {
                scale: rand(0.5,2),
                x : rand(0, $('body').width()),
                y : 0,
                opacity:1.0,
                rotation: rand(0,360)
            };
            this.put();
        }
        //桜更新
        SAKURA.prototype.update = function(idx){
            this.cntX++;
            this.cntY++;
            disX = Math.sin(this.cntX/10)*5;
            disY = Math.sin(this.cntY/5)*2;
            this.$ele.css({
                opacity: this.$ele.css('opacity')-0.005,
                top: parseInt(this.$ele.css('top'),10) + disY + 3,
                left: parseInt(this.$ele.css('left'),10) + disX,
                transform: 'scale(' + this.init.scale + ',' + this.init.scale + ') rotate('+(this.cntX%180)/3+'deg)'
            });
//            if(parseInt(this.$ele.css('top'),10) > $(window).height()){
//                this.remove(idx);
//            }
            if(this.$ele.css('opacity')==0){
              this.remove(idx);
            }

            return true;
        };
        // 桜表示
        SAKURA.prototype.put = function(){
            $('body').append(this.$ele);
            this.$ele.css({
                left: this.init.x,
                top: this.init.y,
                transform: 'scale(' + this.init.scale + ',' + this.init.scale + ')'
            })
        };
        // 桜削除
        SAKURA.prototype.remove = function(idx){
            this.$ele.remove();
            delete sakuras[idx];
        };

        // 桜コンテナ
        var sakuras = [];
        var cnt = 0;

      function update(){
        cnt++;
        if(cnt%2==1){
            // 桜生成
            sakuras.push(new SAKURA());
        }
        sakuras.forEach(function(element,idx){
            element.update(idx);
        });
        frameanime = requestAnimationFrame(update);
      }

      $("#btnstart").click(function(){
        frameanime = requestAnimationFrame(update);
      });
      $("#btnreset").click(function(){
        cancelAnimationFrame(frameanime);
      });


    });
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console