A jQuery plugin for inflating web type

Overview

FitText.js, a jQuery plugin for inflating web type

FitText makes font-sizes flexible. Use this plugin on your responsive design for ratio-based resizing of your headlines.

How it works

Here is a simple FitText setup:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="jquery.fittext.js"></script>
<script>
  jQuery("#responsive_headline").fitText();
</script>

Your text should now fluidly resize, by default: Font-size = 1/10th of the element's width.

The Compressor

If your text is resizing poorly, you'll want to turn tweak up/down "The Compressor". It works a little like a guitar amp. The default is 1.

jQuery("#responsive_headline").fitText(1.2); // Turn the compressor up   (resizes more aggressively)
jQuery("#responsive_headline").fitText(0.8); // Turn the compressor down (resizes less aggressively)

This will hopefully give you a level of "control" that might not be pixel perfect, but resizes smoothly & nicely.

minFontSize & maxFontSize

FitText now allows you to specify two optional pixel values: minFontSize and maxFontSize. Great for situations when you want to preserve hierarchy.

jQuery("#responsive_headline").fitText(1.2, { minFontSize: '20px', maxFontSize: '40px' });

CSS FAQ

  • ⚠️ Run FitText before anything that hides the element you're trying to size (e.g. before Carousels, Scrollers, Accordions, Tabs, etc). Hiding an element's container removes its width. It can't resize without a width.
  • ⚠️ Make sure your container has a width!
    • display: inline elements don't have a width. Use display: block OR display: inline-block+ a specified width (i.e. width: 100%).
    • position:absolute elements need a specified width as well.
  • Tweak until you like it.
  • Set a No-JS fallback font-size in your CSS.
  • 🆕 If your text is full width, you might want to NOT use FitText and just use CSS vw units instead. Supported in all major browsers.

Don't use jQuery?

That's okay. Check out these handy non-jQuery versions maintained by other people.

Changelog

  • v 1.2 - Added onorientationchange event
  • v 1.1 - FitText now ignores font-size and has minFontSize & maxFontSize options
  • v 1.0.1 - Fix for broken font-size.
  • v 1.0 - Initial Release

In Use:

If you want more exact fitting text, there are plugins for that! We recommend checking out BigText by Zach Leatherman or SlabText by Brian McAllister.

Download, Fork, Commit.

If you think you can make this better, please Download, Fork, & Commit. We'd love to see your ideas.

Comments
  • Invalid meta in bower.son

    Invalid meta in bower.son

    bower invalid-meta  fittext is missing "main" entry in bower.json
    bower invalid-meta  fittext is missing "ignore" entry in bower.son
    
    Bower 
    opened by teomaragakis 15
  • FitText on Multiple, shared constraint

    FitText on Multiple, shared constraint

    Hi,

    It would be useful to be able to apply FitText to multiple elements (of the same style), and have all of them use the maximum size of any one. If applied to 3 elements, whatever the smallest size is for any of them once resized, should apply to all 3 so the size is consistent across the elements.

    Good work though, enjoying this.

    opened by catchamonkey 13
  • Add Destroy Method?

    Add Destroy Method?

    Hello there!

    I wanted to be able to destroy fitText.js in certain case but instead of asking you to do it, I created another code and I think it might be useful for you or other people

    (function($) {
      var resizer = function (el) {
        var $this = el.data.this
        var settings = el.data.settings
        $this.css('font-size', Math.max(Math.min($this.width() / (settings.compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize)));
      };
    
      var methods = {
        init: function(options) {
          return this.each(function() {
            var $this = $(this);
            var settings = $this.data('fitText');
    
            if(typeof(settings) == 'undefined') {
    
              var defaults = { 
                'compressor'  : 1,
                'minFontSize' : Number.NEGATIVE_INFINITY,
                'maxFontSize' : Number.POSITIVE_INFINITY
              }
    
              settings = $.extend({}, defaults, options);
    
              $this.data('fitText', settings);
            } else {
              settings = $.extend({}, settings, options);
            }
    
            var identifier = 'fittext-'+Date.now()
            $(this).addClass(identifier).data('fittextId', "."+identifier)
    
            $(window).on('resize.'+identifier ,  function(){
              $this.css('font-size', Math.max(Math.min($this.width() / (settings.compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize)));
            }).resize();
    
          });
        },
        destroy: function(options) {
          return $(this).each(function() {
            var $this = $(this);
            $(window).off( $this.data('fittextId') );
            $this.removeData('fitText').css({fontSize: ""});
          });
        },
    
      };
    
      $.fn.fitText = function() {
        var method = arguments[0];
    
        if(methods[method]) {
          method = methods[method];
          arguments = Array.prototype.slice.call(arguments, 1);
        } else if( typeof(method) == 'object' || !method ) {
          method = methods.init;
        } else {
          $.error( 'Method ' +  method + ' does not exist on jQuery.fitText' );
          return this;
        }
    
        return method.apply(this, arguments);
    
      }
    
    })(jQuery);
    

    Then in the html It work that way:

    $("#element").fitTextt({ 
          'compressor'  : 1.6,
           'minFontSize' : "18px",
          'maxFontSize' : "48px",
    })
    
    $("#element").fitTextt("destroy")
    

    cheers, Catherine

    Feature Request 
    opened by ktryndchrs 8
  • Font-size

    Font-size

    I'm new in this people, so please don't shoot me. I'm working on a responsive website. The problem is that when I resize my window everything is allright. But then when I switch to another page in a resized window the font-size is in default. When I just move the resized window a tiny bit it switches back to the font-size it supossed to be.

    Anyone???

    opened by disparvulgo 8
  • I can't seem to make this work (unoriginal title)

    I can't seem to make this work (unoriginal title)

    Hello. I've been trying to apply FitText to a div that I've positioned (prependTo) with jQ.

    Hacky, sure— but I can't see why the final result wouldn't be working. ( Site: https://eventsadmin.sqsp.com pass: events )

    image

    opened by alanhouser 7
  • Infinite shrink

    Infinite shrink

    I've made a video of a problem I keep havng with fittext. Not sure how to describe it other than text infinitely shrinks into a singularity when resizing and I have the preset set to default (1.2)

    $('.call-header span').fitText();

    video - > http://d.pr/v/tpQk

    opened by SephVelut 6
  • Bug in combination with fullPage.js

    Bug in combination with fullPage.js

    I found out that only the first 2 slides in a onepager with fullPage.js (https://github.com/alvarotrigo/fullPage.js) working with FitText.js. Is there a workaround or a fix? I can provide a live website if you want.

    opened by digitalmdma 5
  • Uncaught TypeError: undefined is not a function - Help

    Uncaught TypeError: undefined is not a function - Help

    Hi,

    Chrome is throwing Uncaught TypeError: undefined is not a function all the time. I initialized just like described and used jquery v.2.1.1. I even tried the vanilla js plugin, but I got the same error.

    I´m using it together with Foundation & Modernizer if that matters.

    Here´s the code:

    <script src="js/vendor/jquery.js"></script>
    <script src="js/vendor/fittext.js"></script>
    <script>
            $('#headline_main').fitText(1.2);
            $('#headline_second').fitText(1.2); 
    </script>
    
    opened by florian-oefner 5
  • Doesn't work proper with one word only?

    Doesn't work proper with one word only?

    To me it seems like it downsizes titles too much, especially on short words, see this example: http://duotones.ch/article/spring.html

    While it works perfectly on this example: http://duotones.ch/article/naturkostbar.html

    Settings are the following:

    
    jQuery(".fittext").fitText(0.87, { minFontSize: '30px', maxFontSize: '119px' });
    

    or am I missing something?

    opened by marcelhadorn 5
  • [Improving performance] Using the style.fontSize and style.width

    [Improving performance] Using the style.fontSize and style.width

    Through the use of native features js good performance is proven;

    Compare performance (style):

    fontSize: http://jsperf.com/resizers **(new) > width: http://jsperf.com/jquery-css-vs-width-vs-native-width/2

    opened by saintclair 5
  • Resize doesn't occur on chrome when exiting

    Resize doesn't occur on chrome when exiting "device toolbar"

    Issue: When resizing the viewport in chrome using the device toolbar, if you click the icon to disable the device toolbar when your viewport goes back to full size, text does not resize back up to the native/max size.

    Env: Chrome: Version 67.0.3396.99 (Official Build) (64-bit) OS: OSX 10.13.6

    Duplicate: Open developer tools in chrome, click the button for device toolbar (bottom left next to the element select arrow), resize the viewport, click the button to disable the device toolbar, text does not resize necessitating a page refresh.

    opened by bellwood 0
  • FitText on bootstrap navbar links

    FitText on bootstrap navbar links

    Hi, I tried to implement fit text in bootstrap navbar links so the font size is different on xl, lg, and even on sm screens when it collapses so i will not have to add media queries but it does not work it always keeps the max size. Any help ? Thanks

    opened by savgiannis 2
  • Bug with Bootstrap's Open Dropdown Menu

    Bug with Bootstrap's Open Dropdown Menu

    In Bootstrap, it seems to only scale the font size if the menu is opened. If it's closed, there's no font scaling happening. (This is probably intended functionality -- because the items aren't visible).

    I'd like to note two things:

    1. On initial page load, it isn't setting a font size to these list items in the dropdown. (Probably because it's closed and they're not visible).

    2. If a dropdown menu is "opened", the font is continuously enlarged on screen resize.

    I haven't tested yet, but I would assume this true for all dynamically hidden/visible items on a page.

    I love this script, but I also love using Bootstrap. It would be nice if it integrated well with Bootstrap's concepts.

    opened by michael-ecklund 1
Releases(v1.2.0)
Owner
Dave Rupert
Lead developer at Paravel. Purveyor of tiny jQueries.
Dave Rupert
jQuery plugin, calculates the font-size and word-spacing needed to match a line of text to a specific width.

BigText BigText Makes Text Big Read the original blog post Play around on the demo Watch the video Download bigtext.js Or use bower: bower install big

Zach Leatherman 883 Dec 15, 2022
Text Neon Golden effect jQuery plug-in

novacancy.js novacancy.js is a text neon golden effect jQuery plugin. Demo Visit demo site Basic Usage Just use $('#no').novacancy(); or detail $('#no

Chuck Chang 185 Sep 24, 2022
Web typography at its finest: font-size and line-height based on element width.

FlowType.JS Responsive web typography at its finest: font-size and line-height based on element width. Check out the demo site. What does FlowType.JS

Simple Focus 4.6k Dec 30, 2022
A lightweight, easy to use Javascript injector for radical Web Typography

Lettering.js, a jQuery plugin for radical Web Typography We developed a lightweight, easy to use Javascript span injector for radical Web Typography,

Dave Rupert 5.4k Dec 20, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Type predicate functions for checking if a value is of a specific type or asserting that it is.

As-Is Description As-Is contains two modules. Is - Type predicates for checking values are of certain types. As - Asserting values are of a certain ty

Declan Fitzpatrick 8 Feb 10, 2022
Combine type and value imports using Typescript 4.5 type modifier syntax

type-import-codemod Combines your type and value imports together into a single statement, using Typescript 4.5's type modifier syntax. Before: import

Ian VanSchooten 4 Sep 29, 2022
🧬 A type builder for pagination with prisma and type-graphql.

?? Prisma TypeGraphql Pagination Prisma TypeGraphql Pagination builds prisma pagination types for type-graphql. import { ... } from 'type-graphql'

Arthur Fiorette 2 Apr 21, 2022
🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

?? HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Ronen Amiel 1.8k Dec 20, 2022
A type programming language which compiles to and interops with type-level TypeScript

Prakaar Prakaar (hindi for "type") is a type programming language which compiles to and interops with type-level TypeScript. Prakaar itself is also a

Devansh Jethmalani 17 Sep 21, 2022
A transpiler from golang's type to typescript's type for collaboration between frontend & backend.

go2type go2type.vercel.app (backup site) A typescript transpiler that convert golang's type to typescript's type. Help front-end developer to work fas

Oanakiaja 8 Sep 26, 2022
100% type-safe query builder for node-postgres :: Generated types, call any function, tree-shakable, implicit type casts, and more

⚠️ This library is currently in alpha. Contributors wanted! tusken Postgres client from a galaxy far, far away. your database is the source-of-truth f

alloc 54 Dec 29, 2022
A jQuery plugin that creates a paneled-style menu (like the type seen in the mobile versions of Facebook and Google, as well as in many native iPhone applications).

#jPanelMenu ###Version 1.4.1 jPanelMenu is a jQuery plugin for easily creating and managing off-canvas content. Check out the demo (and documentation)

Anthony Colangelo 927 Dec 14, 2022
This is a jquery ui sortable helper plugin for handy tree type structure sotable.

Tree Sortable A drag and drop list item sorting and level changing library. Motivation The jQuery-ui's sortable plugin allows us to sort items vertica

Sajeeb Ahamed 10 Dec 23, 2022
JQuery-TableToExcel - Light weight jQuery plugin for export HTML table to excel file

tableToExcel Light weight jQuery plugin for export table to excel file Demos Website and demo here: http://tanvirpro.com/all_project/jQueryTableToExce

Tanvir Sarker 4 May 8, 2022
Jquery-cropper - A jQuery plugin wrapper for Cropper.js.

jquery-cropper A jQuery plugin wrapper for Cropper.js. Demo Main dist/ ├── jquery-cropper.js (UMD) ├── jquery-cropper.min.js (UMD, compresse

Fengyuan Chen 653 Jan 7, 2023
JQuery charCounter - jQuery Character Counter Plugin

jQuery Character Counter A jQuery based character counter for <input> and <textarea> HTML tags. What is this? This simple plugin allows you to add a c

mmmm_lemon 1 Aug 10, 2022
Jquery.iocurve - jQuery plugin like Tone Curve on Photoshop or GIMP

jquery.iocurve jQuery plugin like Tone Curve on Photoshop or GIMP. See Official page for more information. Quick start Create HTML and open in your br

null 5 Jul 28, 2022