Skip to: Content or Footer

Fit Text – What a difference a Dave makes

Introduction

Whilst looking into a project in which I wanted ‘large scalable responsive text’ I tried out various JavaScript packages. In the past I would have used Dave Rupert’s FitText but that utilises jQuery which I moved away from quite some time ago.

There have been other non jQuery versions along the way but they all require ‘coaxing’ to get what you need in terms of ‘full width.’

Fitty JavaScript Library Animation
Fitty JavaScript Library Animation

I finally found the Fitty Library from Rik Schennink. Perfect for what I required… To a point.

Using Fitty JS

For full width with no adjustments the library is ‘almost’ perfect. It can on occasion require a page reload which isn’t ideal. Then there’s a big issue with the height of the container parent.

The only way I could think of was to add some extra code in the section that adds the inline code making the height of the container the same size as the font…

v = function (e) {
  (e.element.style.whiteSpace = e.whiteSpace),
  (e.element.style.display = e.display),
  (e.element.style.fontSize = e.currentFontSize + "px");
},

I added…

(e.element.style.height = e.currentFontSize + "px");

So we end up with…

v = function (e) {
  (e.element.style.whiteSpace = e.whiteSpace),
  (e.element.style.display = e.display),
  (e.element.style.fontSize = e.currentFontSize + "px"),
  (e.element.style.height = e.currentFontSize + "px");
},

This was in an effort to allow for variable widths and font sizes…

          WHAT A          
     DIFFERENCE A     
 DAVE 
   MAKES   

All in all, after editing the script itself, then having to add lots of whitespaces ( ) to create the ‘padding’ needed to emulate the different ‘widths’ I decided that I was “on a hiding to nothing.”

Using SVG Text

The alternative is to use good old SVG, my only reticence is making them all accessible. If anyone has any comments about how best to handle something like the example below, please get in touch, I’m all ears.

What a WHAT A
difference a DIFFERENCE A
Dave DAVE
makes MAKES

Download sample code

I’ve assembled all the parts so that you can play with them. The standard – software is provided “as is”, without warranty of any kind – applies here.

Download File
Zip Files Info
cooper-std-black.woff2
22.3KB
index.html
2.5KB
fitty.min.js
6.6KB
style.css
2.4KB
readme.txt
460 bytes
File: barrd-what-a-diff-dave.zip
Details: 5 files @ 30.1KB

That’s all folks

This is more of a template for me to play with but you’re welcome to have a play too. If you have any comments about making SVG‘s more accessible I’m always open to hearing about them.

// End of Project

More Information

Dave Barr

Bristol based Scottish Expat who has 20+ years experience of Web Development and is continually on the look out to improve his skill sets. Learning new and innovative solutions for current requirements in the world of IT, WebDev and eCommerce.

About Dave Barr

Image for Dave Barr
Bristol based Scottish Expat who has 20+ years experience of Web Development and is continually on the look out to improve his skill sets. Learning new and innovative solutions for current requirements in the world of IT, WebDev and eCommerce.

Read more about Dave

Click to Copy