From 533d80d350f0d174c76f41f3f743d28437d8a0a4 Mon Sep 17 00:00:00 2001 From: Pierrick CAEN Date: Mon, 2 Mar 2015 11:40:21 +0100 Subject: [PATCH] Scale text only if it's visible. --- example.html | 21 +++++++++++++-------- jquery.fittext.js | 5 ++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/example.html b/example.html index c6a2aee..dde01c7 100644 --- a/example.html +++ b/example.html @@ -6,9 +6,9 @@ @@ -41,20 +44,22 @@
-

Squeeze with FitText

-

Squeeze with FitText

-

Squeeze with FitText

+

Squeeze with FitText

+

Squeeze with FitText

+

Squeeze with FitText

+

Hidden text should not be scaled. But will be if we show it.

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

- + - + diff --git a/jquery.fittext.js b/jquery.fittext.js index 0b3ddef..c7b2250 100644 --- a/jquery.fittext.js +++ b/jquery.fittext.js @@ -26,8 +26,11 @@ var $this = $(this); // Resizer() resizes items based on the object width divided by the compressor * 10 + // Resize them only if visible. var resizer = function () { - $this.css('font-size', Math.max(Math.min($this.width() / (compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize))); + if($this.is(':visible')) { + $this.css('font-size', Math.max(Math.min($this.width() / (compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize))); + } }; // Call once to set.