Skip to content

Instantly share code, notes, and snippets.

@edwardhotchkiss
Created September 26, 2013 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardhotchkiss/6708316 to your computer and use it in GitHub Desktop.
Save edwardhotchkiss/6708316 to your computer and use it in GitHub Desktop.
Creates an HTML Grid for debugging Animations
/**
* @library DebugGrid
* @author CandidBlend <hi@candidblend.la>
* @description grid for debugging, layouts & demos
* @license MIT
*/
(function() {
'use strict';
/**
* @class DebugGrid
* @description constructor
*/
var DebugGrid = window.DebugGrid = function() {
var $row, $grid, $square, $infobox, cw, ch, ww, wh, z = 1, sz = 40;
ww = $(window).width();
wh = $(window).height();
cw = Math.floor(ww / sz) - 1;
ch = Math.floor(wh / sz) - 1;
$grid = $('<div id="grid"></div>');
$('body').append($grid);
for (var a = 0; a < cw; a++) {
for (var b = 0; b < ch; b++) {
$square = $('<div class="grid-square"></div>')
.attr('id', 'grid-square-' + z);
_positionSquare($square, (a * sz), (b * sz), z);
$grid.append($square);
z++;
}
}
$infobox = $('<div class="info-box"><p></p></p></p></div>').css({
top : 60,
left : ((cw * sz) - 220),
});
$grid.append($infobox);
_positionGridAndStage(ww, wh, cw, ch, sz);
return $grid;
};
/**
* @private _positionGridAndStage
*/
function _positionGridAndStage(ww, wh, cw, ch, sz) {
return $('#stage, #grid').css({
"top": (wh - (ch * sz)) / 2,
"left": (ww - (cw * sz)) / 2,
"width": cw,
"height": ch
});
}
/**
* @private _positionSquare
*/
function _positionSquare($square, x, y, z) {
return $square.css({
"top": y,
"left": x,
"z-index": z
});
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment