Last active
October 6, 2016 17:01
-
-
Save danemacaulay/9ed6254c183991c4ca493470a483dfda to your computer and use it in GitHub Desktop.
dirty hack to reduce element sizing
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
'use strict'; | |
var _ = require('lodash'); | |
function stripPx(val) { | |
return val.replace('px', ''); | |
} | |
function addPx(val) { | |
return val + 'px'; | |
} | |
function reduceSize(val) { | |
return val / 2; | |
} | |
var els = document.body.getElementsByTagName('*'); | |
var count = els.length; | |
var properties = [ | |
'font-size', | |
'line-height', | |
'margin-left', | |
'margin-right', | |
'margin-top', | |
'margin-bottom', | |
'padding-left', | |
'padding-right', | |
'padding-top', | |
'padding-bottom', | |
]; | |
while(count--){ | |
var el = els[count]; | |
var calc = window.getComputedStyle(el); | |
properties.forEach(function (prop) { | |
var camelCased = _.camelCase(prop); | |
el.style[camelCased] = addPx(reduceSize(stripPx(calc.getPropertyValue(prop)))); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment