Skip to content

Instantly share code, notes, and snippets.

Avatar

Nabil Redmann BananaAcid

View GitHub Profile
@BananaAcid
BananaAcid / autoshrink.js
Last active Oct 20, 2016 — forked from andrewbranch/autoshrink.js
Responds to window resize events. Max font size taken from initial font size (specify with CSS). [no modifications, just forked to extend the example.]
View autoshrink.js
(function($) {
function getTextWidth($element) {
var tester = $("<div/>").text($element.text())
.css({ "position": "absolute", "float": "left", "white-space": "nowrap", "visibility": "hidden", "font": $element.css("font"), "text-transform": $element.css("text-transform"), "letter-spacing": $element.css("letter-spacing") })
.appendTo($element.parent()),
width = tester.innerWidth();
tester.remove();
return width;
}