Created
September 26, 2017 11:07
-
-
Save carolina-vallejo/3bbbf26a0f81250fdb14238505649161 to your computer and use it in GitHub Desktop.
font responsive #javascript
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
$(window).load(function() { | |
//----ADJUST FONTSIZE IN MOBILE | |
if (isMobile()) { | |
$('h1, h2, h3, h4').each(function() { | |
var $this = $(this); | |
var text = $this.text(); | |
$this.empty().append('<span style="color:inherit">' + text + '</span>'); | |
var width = $this.width(); | |
var actfont = parseInt($this.css('font-size').replace('px', '')); | |
var $spanText = $this.find('span'); | |
for (var i = 1; i < actfont; i++) { | |
var scrollw = $spanText.width(); | |
if (scrollw > width) { | |
console.log('scrollw: ' + scrollw + ' width: ' + $spanText.width()); | |
$spanText.css({ | |
'font-size': (actfont - i) + 'px' | |
}); | |
} else { | |
break; | |
} | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment