GithubHelp home page GithubHelp logo

fittext.js's Introduction

#FitText(content).js, a plugin for not pissing off your designers. This adaptation of FitText makes groups of elements resize to the same size. Use case: You have a bunch of navigation items that fit beautifully within their respective containers in the nav bar. But then you translate the site to another language. And only one doesn't fit. Regular FitText will only change the size of the one that overflows. And then your designers will yell at you for ruining everything. But not with FitText(content)! FitText content will resize all of the items to the size of the one that originally didn't fit. Yay! And no jQuery! And the source is in ES6! And it's React-ready with a handy dismount function!

##To Use

###in ES6

import FitText from './fittext-content';

const headers = document.getElementsByTagName('h1');

const fitElements = new FitText(headers);

###Regular JS

var FitText = require('./fittext-content'),
	headers = document.getElementsByTagName('h1'),
	fitElements = new FitText(headers);

Basically the same.

###Alt Syntax If you're not sure whether any elements exist, it's probably safer to instantiate this way:

[].slice.call(headers).forEach( header => {
	new FitText(header);
});

This will avoid errors if the headers variable doesn't contain anything.

###For single-page apps The dismount function should be called when the element is removed from the page

fitElements.dismount();

###Options FitText(content) takes all the regular ol' options from it's predecessor.

new FitText(header, .8, {minFontSize: 20, maxFontSize: 40});

fittext.js's People

Contributors

davatron5000 avatar efollender avatar boldewyn avatar tsvensen avatar arthurvr avatar danferth avatar codler avatar jeffpersonified avatar kevinsawicki avatar fernahh avatar neilmonroe avatar plfstr avatar charliewilco avatar darcyclarke avatar jpfotoz avatar

Stargazers

kenfrederick avatar David Aerne avatar Joshua Conner avatar Felipe Leão avatar Alex Jones avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.