Pen Settings

HTML

CSS

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

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

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.

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

              
                <body>
  <div class="animated-background"></div>
</body>
              
            
!

CSS

              
                body{
  width: 100vw;
  height: 100vh;
  box-sizing: border-box;
  padding: 5px;
  margin: 0;
  overflow: hidden;
}

.animated-background{
  position: relative;
  width:100%;
  height:100%;
}

.animated-background > div.animated-sub{
  z-index: -10;
  position: absolute;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

.animated-background > div.animated-sub > div{
  position: absolute;
  height: 100%;
  /*transform: translate(50% , 50%);
  right: 50%;
  bottom: 50%;*/
}

.green-square{
  position:relative;
  display: inline-block;
  float: left;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #ddd;
  transition: all 2s ;
}

              
            
!

JS

              
                //start animated background
$(function(){  
  var squareSize = 40; // size of squares
  var amount = 100 ; // a number from 1 to 1000 : displays more or less squares
  var interval = 200 ; // interval to regenerate squares in miliseconds
  var squareLife = 1000 ; // duration of each before it disapeears
   var colors = ['#F96', '#F33', '#f5d000', '#d2d002', ':#6C9', '#008e8c', '#bd4f82' ] ;
  
$(window).on('load' , function(event){
           $('.animated-background').prepend('<div class="animated-sub"><div></div></div>');
  var canvasWidth = $('.animated-background').width() ;
  var xSquares = Math.ceil(canvasWidth/squareSize) + 1 ;
  var canvasHeight = $('.animated-background').height() ;
  var ySquares = Math.ceil(canvasHeight/squareSize) + 1;
  var totalSquares = xSquares * ySquares ;
  var greenSquareStyle = 'style="width: ' + squareSize + 'px; height: ' + squareSize + 'px;"' ;
  var realWidth = +canvasWidth + +squareSize + +squareSize ;

$('head').append('<style class="animated-width">.animated-background > div.animated-sub > div{ width: ' + realWidth + 'px;}</style>');
  for (i = 0 ; i < totalSquares ; i++) {
    $('.animated-background > div.animated-sub > div').append('<div class="green-square"' + greenSquareStyle + '></div>') ;
  }
  });
 
  
  
  
$(window).on('resize' , function(event){
             $('.animated-background').empty();
           $('.animated-background').prepend('<div class="animated-sub"><div></div></div>');
  var canvasWidth = $('.animated-background').width() ;
  var xSquares = Math.ceil(canvasWidth/squareSize) + 1 ;
  var canvasHeight = $('.animated-background').height() ;
  var ySquares = Math.ceil(canvasHeight/squareSize) + 1;
  var totalSquares = xSquares * ySquares ;
  var greenSquareStyle = 'style="width: ' + squareSize + 'px; height: ' + squareSize + 'px;"' ;
  var realWidth = +canvasWidth + +squareSize + +squareSize ;
  $('.animated-width').remove() ;
$('head').append('<style class="animated-width">.animated-background > div.animated-sub > div{ width: ' + realWidth + 'px;}</style>');
  for (i = 0 ; i < totalSquares ; i++){
    $('.animated-background > div.animated-sub > div').append('<div class="green-square"' + greenSquareStyle + '></div>') ;
  }
  }); 
 

  window.setInterval(function(){
    var totalSquares = $(".green-square").length ;
    var randSquareLevel = amount ;
    var randSquareRatio = randSquareLevel / 1000;
    var randSquareCount =  Math.ceil(randSquareRatio * totalSquares) ;
    for(i = 0 ; i < randSquareCount ; i++){ 
       function getRandomColor() {
	      return colors[Math.floor(Math.random()*colors.length)];
	  }
   var RandomColor = getRandomColor();
    function randomArray(){
      var randSquare = Math.random();
      var randSquareNumber = Math.floor(totalSquares * randSquare);
      var coloredSquares = $(".green-square").eq(randSquareNumber);
         $(coloredSquares).css({"background-color":RandomColor});
         setTimeout(function(){ $(coloredSquares).css({"background-color":""}); }, squareLife); 
      };
       
        randomArray(); 

      } //for
    
 },interval); //settimeout

  
  });
              
            
!
999px

Console