Skip to content

Instantly share code, notes, and snippets.

@onebytegone
Last active June 19, 2018 13:35
Show Gist options
  • Save onebytegone/178b34a5cb8f10ff5a4811e4d42e69cc to your computer and use it in GitHub Desktop.
Save onebytegone/178b34a5cb8f10ff5a4811e4d42e69cc to your computer and use it in GitHub Desktop.
Datadog ScreenBoard Grid Aligner
$('.widget').each(function() {
var GRID_SIZE = 12,
el = $(this),
title = el.find('.title_text').text(),
roundToGrid;
roundToGrid = function(value) {
return Math.ceil(value / GRID_SIZE) * GRID_SIZE;
};
console.log('%s - BEFORE left: %s, top: %s, width: %s, height: %s', title, el.css('left'), el.css('top'), el.width(), el.height());
el.css('left', roundToGrid(parseInt(el.css('left'), 10)) + 'px');
el.css('top', roundToGrid(parseInt(el.css('top'), 10)) + 'px');
el.height(roundToGrid(el.height()));
el.width(roundToGrid(el.width()));
console.log('%s - AFTER %s, top: %s, width: %s, height: %s', title, el.css('left'), el.css('top'), el.width(), el.height());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment