GithubHelp home page GithubHelp logo

tythewebguy / text-balancer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nytimes/text-balancer

0.0 0.0 0.0 11 KB

Eliminate typographic widows and other type crimes with this javascript module

License: Other

JavaScript 100.00%

text-balancer's Introduction

text-balancer

Text-balancer is a javascript module that seeks to eliminate typographic widows from text. It does this by setting the max-width of the dom node to the threshold that it would spill onto another line.

Setup instructions

Install it into your project via npm

npm install text-balancer --save

https://www.npmjs.com/package/text-balancer

We use bramstein's Font Face Observer to check when our fonts have loaded: https://github.com/bramstein/fontfaceobserver

We run our text-balancer once our fonts load.

How to run it

import textBalancer from 'text-balancer';

// Run it when you want to with any set of selectors
textBalancer.balanceText('.headline, .interactive-leadin, #horse-god');

// OR: Just run it and it will look for anything with the balance-text class
textBalancer.balanceText();

If you're not running node/npm

Include text-balancer.standalone.js wherever you load your js files
and then:
PUT THIS SCRIPT AFTER YOUR MARKUP IDEALLY UNDER THE BODY TAG
OR JUST WRAP IT IN SOME SORT OF AN ONLOAD EVENT :)
<script>
// Run it when you want to with any set of selectors
textBalancer.initialize('.headline, .interactive-leadin, #horse-god');

// OR: Just run it and it will look for anything with the balance-text class
textBalancer.balanceText();
</script>

text-balancer's People

Contributors

mbeswetherick avatar da2x avatar tythewebguy avatar flavioribeiro avatar liddiard 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.