Last active
August 29, 2015 14:04
-
-
Save dfernandez79/557bff27f0b6223b2a9b 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 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.__toggleColGrid){s=d.createElement('script');s.src='https://rawgit.com/dfernandez79/557bff27f0b6223b2a9b/raw/column-grid.js';d.body.appendChild(s);s.onload = function() { w.__toggleColGrid() }; }else{w.__toggleColGrid();}})(document,window); |
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
(function (global) { | |
'use strict'; | |
function createColGrid(id, width, gap, cols) { | |
width = width? width : 30; | |
gap = gap? gap : 5; | |
cols = cols? cols : 40; | |
var | |
halfWidth = width/2, | |
grid = document.createElement('div'); | |
grid.id = id; | |
grid.style.display = '-webkit-flex'; | |
grid.style.display = 'flex'; | |
grid.style.position='fixed'; | |
grid.style.top = 0; | |
grid.style.left = 0; | |
grid.style.right = 0; | |
grid.style.bottom = 0; | |
grid.style.opacity = 0.3; | |
grid.style.boxSizing = 'border-box'; | |
grid.style.margin = 0; | |
grid.style.padding = 0; | |
function createColumn() { | |
var col = document.createElement('div'); | |
col.style.width = width + 'px'; | |
col.style.boxSizing = 'border-box'; | |
col.style.backgroundColor = 'rgba(255, 0, 0, 0.1)'; | |
col.style.margin = '0 ' + gap + 'px'; | |
col.style.flex = 'none'; | |
col.style.webkitFlex = 'none'; | |
col.style.position = 'relative'; | |
var half = document.createElement('div'); | |
half.style.width = halfWidth + 'px'; | |
half.style.boxSizing = 'border-box'; | |
half.style.borderRight = '1px solid rgba(0,0,0,0.1)'; | |
half.style.position = 'absolute'; | |
half.style.left = 0; | |
half.style.top = 0; | |
half.style.bottom = 0; | |
col.appendChild(half); | |
return col; | |
} | |
for (var i = 0; i < cols; i++) { | |
grid.appendChild(createColumn()); | |
} | |
return grid; | |
} | |
window.___createColgrid = createColGrid; | |
window.__toggleColGrid = function () { | |
var cg = document.getElementById('___colGrid'); | |
if (!cg) { | |
document.body.appendChild(createColGrid('___colGrid')); | |
} else { | |
cg.style.display = cg.style.display === 'none' ? 'flex' : 'none'; | |
} | |
}; | |
})(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.