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

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

              
                <div id="content" class="contentino" onMouseOut="mouseOnContent(false)" onMouseOver="mouseOnContent(true)"><canvas id="canvas"></canvas></div>
              
            
!

CSS

              
                html, body {
    /*background: transparent !important;*/
    background-color: rgb(0,0,255);
    margin: 0;
    border: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}
#canvas {
    position: fixed;
    background: transparent;
    width: inherit;
    height: inherit;
}
.contentino {
    border-radius: 0px;
    border: none;
    background: rgba(0, 0, 0, 0);
    position: absolute;
    overflow: hidden;
    display: block;
    z-index: 4;
}
              
            
!

JS

              
                gsap.defaults({overwrite: "true"});
CustomEase.create("ew","M0,0,C0,0,0.114,0.85,0.134,0.932,0.178,1.16,0.242,1.028,0.246,1.01,0.264,0.958,0.253,1.009,0.28,0.876,0.312,0.716,0.356,0.834,0.37,0.882,0.384,0.931,0.379,0.965,0.41,1.006,0.46,1.088,0.484,1.022,0.53,0.997,0.58,0.964,0.667,1.002,0.725,1.004,0.829,1.008,1,1,1,1");
var multiplexer=16;
let maxAnimationLength = 1.5;
let elementAnimationTime = .75;
let x_elem= 0; 
let y_elem= 0;
let canAnimate = false;
let doAnimate = true;
var extra_height=0;
////
    var tiles=[];
    var canvas = document.querySelector("#canvas");
    var context = canvas.getContext("2d");
    function render() {
        context.clearRect(0, 0, canvas.width, canvas.height);
        for (var i = 0; i < tiles.length; i++) {
            var tile = tiles[i];
            tile.draw(context);
        }
    }

function setDimensions() {
	intW = window.innerWidth-80;
	intH = window.innerHeight+extra_height;
	scaled_img_w = Math.ceil((intW)*0.9);
	scaled_img_h = Math.floor((intH)*0.75);
	img_x = Math.ceil(((intW/2)-(scaled_img_w/2)));
	img_y = Math.ceil(((intH/2)-(scaled_img_h)/2))-14;
	if (document.getElementById) {
        var theIframe = document.getElementById("content");
        if (theIframe) {
			      theIframe.style.width = Math.ceil((scaled_img_w+40)/10)*10+"px";
			      theIframe.style.height = Math.ceil((scaled_img_h)/10)*10+"px";
            let ofx = Math.ceil((img_x+12)/10)*10;
			      theIframe.style.marginLeft = ofx+"px";
            let ofy = Math.ceil((img_y-16)/10)*10;
			      theIframe.style.marginTop = ofy+"px";
            canvas.width = gsap.getProperty("#content","width");
            canvas.height = gsap.getProperty("#content","height");
        }
	}
}
window.onresize = function() {
	  tiles=[];
    gsap.ticker.remove(render);
	  setDimensions();
    drawSquares();
}
//initilize animation on enter
function loadContent(){
   setDimensions();
                ////
                x_elem= Math.ceil(gsap.getProperty("#content","width")/multiplexer);
                y_elem= Math.ceil(gsap.getProperty("#content","height")/multiplexer)+1;
                console.log("total:: ",x_elem,y_elem ,"("+(x_elem*y_elem)+")")
                //perfOpt(x_elem*y_elem);
                let rnd = Math.floor(gsap.utils.random(0,(x_elem*y_elem)));
                for(let i_x=0;i_x<x_elem;i_x++){
                    for(let i_y=0;i_y<y_elem;i_y++){
                        var tile = createTile(((i_x*(multiplexer))+(multiplexer/4)), ((i_y*(multiplexer))+(multiplexer/4)), 0, 0, "rgba(255,255,255,1)");
                        tiles.push(tile);
                    }
                }
                gsap.to(tiles, {duration:maxAnimationLength,x:"-="+(multiplexer/4),y:"-="+(multiplexer/2),fill:"rgba(0,0,0,.4)",width:"+="+(multiplexer),height:"+="+(multiplexer),ease:"ew",stagger:{grid:[x_elem,y_elem],from:rnd,amount:elementAnimationTime},onComplete:swapBg});
                gsap.ticker.add(render);                
}
function createTile(x, y, width, height, fill) {  
  var tile = {
    x: x,
    y: y,
    width: width,
    height: height,
    fill: fill,
    draw: function(context) {
      context.fillStyle = this.fill;
      context.fillRect(this.x, this.y, this.width, this.height);
    }
  };
  return tile;
}
//landing point after initial animation
function swapBg(){
   document.addEventListener("click", printMousePos);
    //$('#content').empty();
    //gsap.to("#content",{duration:1,borderRadius: 18})
    //gsap.set("#content",{background: "rgba(0, 0, 0, .4)"});
}

//onn window resize pdate
function drawSquares (){
        x_elem= Math.ceil(gsap.getProperty("#content","width")/multiplexer);
        y_elem= Math.ceil(gsap.getProperty("#content","height")/multiplexer)+1;
        let rnd = Math.floor(gsap.utils.random(0,(x_elem*y_elem)));
        for(let i_x=0;i_x<x_elem;i_x++){
            for(let i_y=0;i_y<y_elem;i_y++){
                var tile = createTile(i_x*(multiplexer), i_y*(multiplexer), multiplexer, multiplexer, "rgba(0,0,0,.4)");
                tiles.push(tile);                        
            }
    }
    gsap.ticker.add(render);
}
//on click events
function reanim(t,x_lim,y_lim){
    if(doAnimate){
       //calculation to get surrounding tiles from point of origin
        let saveTiles = tiles;
        let start_At_X = 0;
        let end_At_X = 0;
        let start_At_Y = 0;
        let end_At_Y = 0;
        let maxSurroundElems = 10;
        //x validity
        if((x_lim-maxSurroundElems)<0){
            start_At_X = 0;
        }else{
            start_At_X = (x_lim-10);
        }
        ///
        if((x_lim+maxSurroundElems)>x_elem){
            end_At_X = x_elem;
        }else{
            end_At_X = (x_lim+10);
        }
        //y validity
        if((y_lim-maxSurroundElems)<0){
            start_At_Y = 0;
        }else{
            start_At_Y = (y_lim-10);
        }
        ///
        if((y_lim+maxSurroundElems)>y_elem){
            end_At_Y = y_elem;
        }else{
            end_At_Y = (y_lim+10);
        }
        console.log(start_At_X,end_At_X,start_At_Y,end_At_Y)
        let xps = end_At_X-start_At_X;
        let yps = end_At_Y-start_At_Y;
        ////
       //here we get new arr of tiles that only should be animated
       /*let op = [];
       for(let xd=start_At_X;xd<end_At_X;xd++){
            for(let yd=start_At_Y;yd<end_At_Y;yd++){
                var tile = createTile(xd*(multiplexer), yd*(multiplexer), multiplexer, multiplexer, "rgba(0,0,0,.4)");
                op.push(tile);
            }
        }*/
        let ofseter = (multiplexer/2);
        //grid:[x_elem,y_elem],
        //let tyt= tiles.slice(0,10)
        //console.log(tyt)
        gsap.to(tiles, {x:"+="+(ofseter/2),y:"+="+(ofseter/2),width:"-="+(ofseter),height:"-="+(ofseter),duration:maxAnimationLength/4,ease:"Circ.in",stagger:{grid:[x_elem,y_elem],from:t,amount:elementAnimationTime/2},onStart:function(){doAnimate = false;}});
        gsap.to(tiles, {x:"-="+(ofseter/2),y:"-="+(ofseter/2),width:"+="+(ofseter),height:"+="+(ofseter),duration:maxAnimationLength/2,ease:"ew",delay:(maxAnimationLength/4)+.1,stagger:{grid:[x_elem,y_elem],from:t,amount:elementAnimationTime},
                        onComplete:function(){
                            doAnimate=true;
                        }});
        gsap.ticker.add(render);
    }
}
function printMousePos(event) {
    if(canAnimate){
        let xc = Math.ceil(((event.clientX)-$('#content').offset().left)/multiplexer);
        let yc = Math.ceil(((event.clientY)-$('#content').offset().top)/multiplexer);
        reanim((((xc-1)*(y_elem-1))+(xc-1)+(yc-1)),(xc-1),(yc-1));
    }
}
function mouseOnContent(s){
    canAnimate = s;
}
loadContent();
              
            
!
999px

Console