Code Monkey home page Code Monkey logo

ng-transiterate's Introduction

ng-transiterate

Build Status

AngularJS directive for eased iteration display

illustration

Demo

A working demo can be foud at the project's website: http://witq.github.io/ng-transiterate

Install

The preferred installation method is just using Bower, like that:

$ bower install ng-transiterate

By default, only the core directive is installed in the unminified version. If you want to load additional easing equations, you can customize your bower.json file with the following:

{
  "dependencies": {
    "ng-transiterate": "~1.1"
  },
  "overrides": {
    "ng-transiterate": {
      "main": [
        "dist/ng-transiterate.js", // required
        "dist/ng-transiterate.easings.js" // optional
      ]
    }
  } 
}

Or, for the minified versions:

{
  "dependencies": {
    "ng-transiterate": "~1.1",
    ...
  },
  "overrides": {
    "ng-transiterate": {
      "main": [
        "dist/ng-transiterate.min.js", // required
        "dist/ng-transiterate.easings.min.js" // optional
      ]
    },
    ...
  } 
}

Remember to load the script file in your view:

<script src="bower_components/ng-transiterate/dist/ng-transiterate.js"></script>

If you decide to also load the additional easing equations, add this:

<script src="bower_components/ng-transiterate/dist/ng-transiterate.easings.js"></script>

Then, reference the module (ngTransiterate) in your app:

angular.module('myApp', ['ngTransiterate']);

Use

The directive is very easy to use. The minimal working usage looks like that:

<div transiterate="value"></div>

Where value is any numerical value bound to $scope. The directive sets the element's content to the supplied values and animates any changes.

Optional attributes

duration

Sets the animation duration in miliseconds. Default is 800.

<div transiterate="value" duration="6000"></div>

easing

Sets the easing method. This can be any of the Robert Penner's easing functions. Default it "linearEase". Other easing equations are optional, as described in the installation instructions.

<div transiterate="value" easing="easeOutQuad"></div>

precision

Sets how precisely should floating numbers be displayed. Default is 0 (display as rounded integers). This parameter is used only when no filter is selected.

<div transiterate="value" precision="2"></div>

filter

Sets which angular filter the directive should use for display. Default is none. If a filter requires parameters, they should be passed like that: number:3. This sets the filter to number with optional fractionSize parameter.

<div transiterate="value" filter="number:3"></div>

Setting defaults

The directive comes with some default settings. If you are planning to use it in many places in your app, you can change those defaults in your .config() block, as the transiterateDefaults service can be injected and used as transiterateDefaultsProvider. It has a .setDefault(option, value) method, which can be used to set global app values that all instances of the directive will use:

angular.module('myApp', ['ngTransiterate'])
  .config(function(transiterateDefaultsProvider) {
    transiterateDefaultsProvider.setDefault('duration', 3000);
});

If you want to set multiple options, you can chain the calls:

angular.module('myApp', ['ngTransiterate'])
  .config(function(transiterateDefaultsProvider) {
    transiterateDefaultsProvider
      .setDefault('duration', 6000)
      .setDefault('easing', 'easeOutQuad')
      .setDefault('filter', 'number:3');
});

Contributing

This directive is my first jab at creating something universal and reusable. If you have any ideas how to make it better, PR's and suggestions are welcome.

License

Copyright (c) 2014 Witek Galecki

Licensed under the MIT License

ng-transiterate's People

Contributors

wgalecki avatar witq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ng-transiterate's Issues

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.