Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
- Fixed bug preventing blocks set to 100% width to be scaled
  • Loading branch information
thdoan committed Mar 14, 2014
1 parent 21f8932 commit 5262d44
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions jquery.scalem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Scalem v1.0 - A responsive text jQuery plugin
* Scalem v1.0.1 - A responsive text jQuery plugin
* Copyright 2014, Tom Doan (http://www.tohodo.com/)
*
* Scalem by Tom Doan is licensed under the MIT License.
Expand All @@ -17,7 +17,11 @@
updateStyles = function(o, e) {
var $o = $(o),
/* Create clone to get true text width */
$o2 = $o.clone().css({'display':'none', 'white-space':'nowrap'}),
$o2 = $o.clone().css({
'width': 'auto',
'display': 'none',
'white-space':'nowrap'
}),
/* If data attribute exists, use that instead */
$ref = o.getAttribute('data-scale-reference') ? $(o.getAttribute('data-scale-reference')) : $(oSettings.reference),
/* Array of styles to scale */
Expand All @@ -33,7 +37,10 @@
$o2.appendTo('body');
nTextWidth = $o2.width();
// Exit if something doesn't look right
if (nTargetWidth === 0 || nTextWidth === nRefWidth) return;
if (nTargetWidth === 0 || nTextWidth === nRefWidth) {
$o2.remove();
return;
}
// Scale the text! (6px is minimum font size to get accurate ratio)
for (var i=Math.round((6/$o2.css('font-size', '6px').width())*nTargetWidth); i<nTargetWidth; i++) {
$o2.css('font-size', i + 'px');
Expand Down

0 comments on commit 5262d44

Please sign in to comment.