Skip to content

Instantly share code, notes, and snippets.

@danemacaulay
Last active October 6, 2016 17:01
Show Gist options
  • Save danemacaulay/9ed6254c183991c4ca493470a483dfda to your computer and use it in GitHub Desktop.
Save danemacaulay/9ed6254c183991c4ca493470a483dfda to your computer and use it in GitHub Desktop.
dirty hack to reduce element sizing
'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