Skip to content

Instantly share code, notes, and snippets.

@dfernandez79
Last active August 29, 2015 14:04
Show Gist options
  • Save dfernandez79/64937704c7d3d7750c45 to your computer and use it in GitHub Desktop.
Save dfernandez79/64937704c7d3d7750c45 to your computer and use it in GitHub Desktop.
A bookmarlet source and URL to add a baseline grid to the current page, very useful for CSS development
(function (global) {
'use strict';
function createBaselineGrid(height, lines, bgColor, halfLineColor) {
var
halfHeight = height/2,
grid = document.createElement('div');
grid.id = '___baselineGrid';
grid.style.position='absolute';
grid.style.top = 0;
grid.style.left = 0;
grid.style.right = 0;
grid.style.opacity = 0.1;
grid.style.boxSizing = 'border-box';
grid.style.margin = 0;
grid.style.padding = 0;
grid.style.zIndex = -1;
grid.style.display = 'none';
function createLine(i) {
var line = document.createElement('div');
line.style.height = height + 'px';
line.style.boxSizing = 'border-box';
line.style.backgroundColor = (i % 2 === 0) ? bgColor : 'transparent';
var half = document.createElement('div');
half.style.height = halfHeight + 'px';
half.style.boxSizing = 'border-box';
half.style.borderBottom = '1px solid ' + halfLineColor;
line.appendChild(half);
return line;
}
for (var i = 0; i < lines; i++) {
grid.appendChild(createLine(i));
}
document.body.appendChild(grid);
return grid;
}
window.__toggleBaselineGrid = function (height, lines, bgColor, halfLineColor) {
var bg = document.getElementById('___baselineGrid');
if (!bg) {
height = height || 20;
lines = lines || 400;
bgColor = bgColor || 'lightcoral';
halfLineColor = halfLineColor || 'blue';
bg = createBaselineGrid(height, lines, bgColor, halfLineColor);
}
bg.style.display = bg.style.display === 'none' ? 'block' : 'none';
};
})(window);
javascript:(function (d,w) { var s; if (!w.__toggleBaselineGrid){s=d.createElement('script');s.src='https://rawgit.com/dfernandez79/64937704c7d3d7750c45/raw/baseline-grid.js';d.body.appendChild(s);}else{w.__toggleBaselineGrid(20,400);}})(document,window);
@dfernandez79
Copy link
Author

To use this bookmarlet add the big bookmarklet URL to your bookmarks.

Please note that in order to use the gist, the bookmarklet is using rawgit.com, which has some usage restrictions... don't abuse of the link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment