JSFiddle - React, Tailwind, and code Playground

by dgrebb

JavaScript

(function makeDiv(){
    var divsize = ((Math.random()*100) + 50).toFixed();
    var color = '#'+ Math.round(0xffffff * Math.random()).toString(16);
    $newdiv = $('<div/>').css({
        'width':divsize+'px',
        'height':divsize+'px',
        'background-image': 'url(http://storage.googleapis.com/dgrebb.com/images/bruce-head-cutout.png)',
        'background-size': 'contain',
        'background-repeat': 'no-repeat',
        'transform': 'rotate(' + divsize/2 + 'deg)'
    });
    
    var posx = (Math.random() * ($(document).width() - divsize)).toFixed();
    var posy = (Math.random() * ($(document).height() - divsize)).toFixed();
    
    $newdiv.css({
        'position':'absolute',
        'left':posx+'px',
        'top':posy+'px',
        'display':'none'
    }).appendTo( 'body' ).fadeIn(100).delay(500).fadeOut(200, function(){
       $(this).remove();
       makeDiv(); 
    }); 
})();