Created
April 8, 2014 19:40
-
-
Save maxhoffmann/10178540 to your computer and use it in GitHub Desktop.
fullText.js
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 fullText() { | |
| var elements = [].slice.call(document.querySelectorAll('[data-full-text]')); | |
| elements.forEach(function(element) { | |
| var REGEX_NUMBER = /\d+/; | |
| var REGEX_NO_NUMBER = /[^\d]+/; | |
| element.style.display = "inline"; | |
| element.style.fontSize = ''; | |
| var width = element.getBoundingClientRect().width; | |
| var containerWidth = element.parentNode.getBoundingClientRect().width; | |
| var fontSize = getComputedStyle(element).fontSize; | |
| var fontSizeValue = fontSize.match(REGEX_NUMBER)[0]; | |
| var fontSizeUnit = fontSize.match(REGEX_NO_NUMBER)[0]; | |
| var newFontSize = (fontSizeValue/width)*containerWidth; | |
| element.style.display = ''; | |
| element.style.fontSize = newFontSize + fontSizeUnit; | |
| }); | |
| } | |
| window.addEventListener('DOMContentLoaded', fullText); | |
| window.addEventListener('resize', fullText); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment