Last active
August 29, 2015 14:04
-
-
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
This file contains hidden or 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
(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); |
This file contains hidden or 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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.