Coder Social home page Coder Social logo

powange / ng-fittext.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from patrickmarabeas/ng-fittext.js

0.0 1.0 0.0 554 KB

An AngularJS directive for inflating web type.

Home Page: http://patrickmarabeas.github.io/ng-FitText.js

License: MIT License

JavaScript 46.04% CSS 41.45% HTML 12.51%

ng-fittext.js's Introduction

ng-FitText.js

ng-FitText.js makes font-sizes flexible. Use this AngularJS directive in your fluid or responsive layout to achieve scalable headlines that fill the width of a parent element.

This is a rework of the original jQuery plugin which can be found here: https://github.com/davatron5000/FitText.js.

Install and Inclusion

Grab it with Bower: bower install ngFitText

Include it in your AngularJS application

var myApp = angular.module('myApp', ['ngFitText']);

Apply it to your text

<h1 data-fittext>FitText</h1>

v3.0.0 - NEW! Text now defaults to 100% width!

Specifying a value for data-fittext now allows you to fine tune the font size if you run into issues where font characters visually ooze out of their element.

Models

The FitText directive will also watch the ng-model placed on the element, so go nuts with dynamic content!

Limiting font size

The data-fittext-max="" and data-fittext-min="" attributes respectfully limit the font size. This can also be set globally in the fitTextConfigProvider via min and max.

New lines

To make use of new lines within a single FitText block you will need to use the data-fittext-nl attribute on each line wrapper. See the demo page for an example.

Custom fonts

Fonts may take time to load in. If this is the case, you can use data-fittext-load-delay="" to specify the millisecond delay before size is initially calculated.

Debounce

Because MODULARIZATION, this module doesn't come with debounce functionality included. Instead you will need to specify the functionality in the fitTextConfigProvider:

module.config(['fitTextConfigProvider', function(fitTextConfigProvider) {
  fitTextConfigProvider.config = {
    
    // include a vender function like underscore or lodash
    debounce: _.debounce,
    
    // specify your own function
    debounce: function(a,b,c) {
      var d;return function(){var e=this,f=arguments;clearTimeout(d),d=setTimeout(function(){d=null,c||a.apply(e,f)},b),c&&!d&&a.apply(e,f)}
    },
    
    delay: 1000,
  };
}]);

< v2.4.0

Specifying a value for data-fittext allows you to fine tune the text size. Defaults to 1. Increasing this number (ie 1.5) will resize the text more aggressively. Decreasing this number (ie 0.5) will reduce the aggressiveness of resize. data-fittext-min and data-fittext-max allow you to set upper and lower limits.

<h1 data-fittext=".315" data-fittext-min="12" data-fittext-max="50">ng-FitText</h1>

The element needs to either be a block element or an inline-block element with a width specified (% or px).

Limiting font size

The data-fittext-max="" and data-fittext-min="" attributes respectfully limit the font size. This can also be set globally in the fitTextConfigProvider via min and max.

Debounce

Debouce (limiting the rate at which FitText will be called on window resize) is available. You can pass initialization parameters to the ngFitText constructor to achieve this:

myApp.config( function( fitTextConfigProvider ) {
    fitTextConfigProvider.config = {
        debounce: true, //default is false
        delay: 1000 //default is 250
    };

    // OR

    fitTextConfigProvider.config.debounce = true;
    fitTextConfigProvider.config.delay = 1000;
});

ng-fittext.js's People

Contributors

patrickmarabeas avatar powange avatar richarddavenport avatar zurie avatar davearata avatar

Watchers

 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.