GithubHelp home page GithubHelp logo

jquery-responsive-headlines's Introduction

jQuery Responsive Headlines

by Thomas Kahn

A jQuery plugin for creating responsive one-line headlines that adapt their size to the containing element.

What does it do?

With this jQuery plugin you can create responsive one-line headlines. Instead of wrapping the headline over several rows, this plugin adapts the text size to fit the width of its container on a single line.

A typical user scenario would be if you are building a responsive web site and you want the headlines (some or all) to fit on a single row. On a big screen you want a big headline (large font size) and on a smaller screen you want a smaller headline (small font size). And you want it to change in real time if the user changes the size of the browser window.

It's build on top of jQuery Boilerplate.

How to use it

It works just like any other jquery plugin. Here's a super simple example that turns all h1-tags on the page into responsive headlines:

   $('h1').responsiveHeadlines();

There are also a handfull of options that you can use to customize the behaviour of the plugin. The easiest way to understand what they do is read the comments in the source code and do some experimentation on your own using the HTML demo page which accompanies this code in this repository here on GitHub. But here's an example with some options set, just to get you started:

   $('h1').responsiveHeadlines({
   		container: 'myDiv',
   		maxFontSize: 64,
   		minFontSize: 18
   });

In the example above I have (again) turned all level 1 headers into responsive headlines and I've told them to adjust their width to the width of the element with the class "myDiv", in this case it would most likely be a div on the page. Then I tell it that I want font size to grow up to 64px but no further than that. And I don't want the font size to go below 18 pixles.

So with this code I will get a headline that sits on a single row and has the same width as the div with the class "myDiv" as long as the font size does not go above 64px or below 18px.

jQuery Throttle/Debounce

jQuery Responsive Headlines works best if you use it together with Ben Alman's jquery-throttle-debounce plugin. It's a plugin for controling/limiting the number of calls to a function. In this case it's very useful since the window resize event is triggered very often and the function that determines the size of the text is bound to this event.

Per default jquery-trottle-debounce is used (the option useThrottleDebounce is set to true) and therefore I have included a copy of it in this repository. As I said, for performance reasons I recommend that you use it, but if you for some reason don't want it just set the option useThrottleDebounce to false.

jquery-responsive-headlines's People

Watchers

James Cloos avatar exex zian 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.