Created
September 26, 2013 00:44
-
-
Save edwardhotchkiss/6708316 to your computer and use it in GitHub Desktop.
Creates an HTML Grid for debugging Animations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @library DebugGrid | |
* @author CandidBlend <[email protected]> | |
* @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