Giter Club home page Giter Club logo

angular-ui-router-anim-in-out's Introduction

angular-ui-router-anim-in-out

An animation directive to use with ngAnimate 1.2+ and ui-router

Installation

$ bower install angular-ui-router-anim-in-out --save

or

$ npm i -D angular-ui-router-anim-in-out

Quick Start

  • Include anim-in-out.js & anim-in-out.css on the page
  • Include module as a dependency of your app
angular.module('ExampleApp', ['ngAnimate', 'ui.router', 'anim-in-out'])
  • Configure states as per ui-router instructions
  • Add the animation directive anim-in-out to your ui-view elements by applying the class anim-in-out
<div ui-view="mainView" class="anim-in-out"></div>
  • Finally add classes from the anim-in-out.css to any elements you wish to transition on state change eg. anim-fade, anim-slide-left
<div ui-view="mainView" class="anim-in-out anim-fade" data-anim-speed="1000">

    <!-- Dynamically loaded view content -->
    
    <div class="my-component anim-slide-left"></div>

</div>

Note: you must use absolute positioning of ui-view elements

Usage

Animations are triggered by javascript in order to provide events.

// In your main controller
$rootScope.$on('animStart', function($event, element, speed) {
    // do something
});
    
$rootScope.$on('animEnd', function($event, element, speed) {
    // do something
});

The default transition speed is 1000ms this can be altered using the data-anim-speed attribute on the ui-view. This is optionally further customised by the data-anim-in-speed and data-anim-out-speed attributes.

By default the animation of the incoming state will be triggered after a delay (data-anim-speed / data-anim-in-speed), but this can be changed by setting the attribute data-anim-sync to true.

<div ui-view="mainView" class="anim-in-out" data-anim-sync="true"></div>

FAQs

Why is the position of my views all messed up? Or why are both views visible during the transition?

This directive works as a supplement to ui-router and ngAnimate. The way these two libraries handle transitions is to add both incoming and outgoing views to the dom as sibling nodes, then add/remove the classes required to produce the transition effect. As the view elements exist in parallel in the dom you are required to use absolute positioning to counter the problem of one view effecting the others position.

Gotchas

If you notice a difference in behaviour after compiling your app such as an initial transition failing to trigger the suggestion in this comment/plunkr may help you, or see below:.

angular
    .module('app', ['ngAnimate'])
    .controller('MainCtrl', function ($scope, $timeout, $rootElement) {
        // Monkey-patch for ngAnimate to force animations to be played right
        // on the first digest. A "run-time revert" of this commit:
        // https://github.com/angular/angular.js/commit/eed2333298412fbad04eda97ded3487c845b9eb9
        // Note: dirty hack! Do not use in production code unless you accept
        // all consequences!
        $rootElement.data("$$ngAnimateState").running = false;
    });

Compile Sass

# Install gulp and dependencies
$ npm install

# Compile sass
$ gulp sass

Demo

http://homerjam.github.io/angular-ui-router-anim-in-out/

You may also like

angular-gsapify-router โ€” a similar directive that uses GSAP to power transitions; also features fine grained configuration using a priority attached to each state.

angular-ui-router-anim-in-out's People

Contributors

flomaetschke avatar homerjam avatar winniehell avatar ymhuang0808 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-ui-router-anim-in-out's Issues

Main attribute on bower.json

There is a little problem on bower.json. It's missing css file on main attribute.
Just change the main to and it will work with most plugins for minifying, index injection, etc:
"main": [
"anim-in-out.js",
"css/anim-in-out"
],

Gap between ui-views when sliding left or right

Hi,

Here is the situation:

  • I have a 100% width ui-view set to anim-slide-right
  • all ui-views are position: absolute
  • When sliding right, there is a noticeable gap between the exiting ui-view and entering ui-view

This is causing a problem since you can see the background color through the 'gap'. The size of the gap seems to change depending on the speed and type of easing used.

This can be seen in the official demo page:

http://homerjam.github.io/angular-ui-router-anim-in-out/#/

In the form on the right side, please use these settings:

Speed(ms): 3000
Synchronize Views: True
Main View Style: Slide Right

Also make this tiny adjustment to the css to better visualize the problem (you can run this in the javascript console):

$('head').innerHTML += '<style>#main { border: 1px solid red; }</style>'

It will add a 1px red border around the ui-view so you can see the gap.

Can you provide a solution to this, or help me to understand what is causing this problem?

Thanks in advance! =)

Transition superseded

The library is not supported with this version

Angular 1.6.1
Router ui 0.4.2

Error: transition superseded
    at y [as $get] (http://localhost:63342/mangleWeb/dist/bundle.js?8897a464088b7da8e9bf:9:16087)
    at Object.a [as invoke] (http://localhost:63342/mangleWeb/dist/vendor.min.js?8897a464088b7da8e9bf:88:21911)
    at http://localhost:63342/mangleWeb/dist/vendor.min.js?8897a464088b7da8e9bf:88:22475
    at r (http://localhost:63342/mangleWeb/dist/vendor.min.js?8897a464088b7da8e9bf:88:21279)
    at i (http://localhost:63342/mangleWeb/dist/vendor.min.js?8897a464088b7da8e9bf:88:21584)
    at Object.a [as invoke] (http://localhost:63342/mangleWeb/dist/vendor.min.js?8897a464088b7da8e9bf:88:21805)
    at http://localhost:63342/mangleWeb/dist/vendor.min.js?8897a464088b7da8e9bf:88:28385
    at r (http://localhost:63342/mangleWeb/dist/vendor.min.js?8897a464088b7da8e9bf:88:809)
    at Object.<anonymous> (http://localhost:63342/mangleWeb/dist/vendor.min.js?8897a464088b7da8e9bf:88:28352)
    at Object.a [as invoke] (http://localhost:63342/mangleWeb/dist/vendor.min.js?8897a464088b7da8e9bf:88:21911) 

Trouble with project name

Just wondering why you chose a so difficult name for the project.
If possible shorten the project name to something like:

  • ui-router-animate
  • ui-router-anim
  • ui-router-ng-animate
  • ui-router-ng-anim

P.S I have just download the the module to try it out.
Best of luck

Bower files

Hello,

Firstly, thank for this very nice plugin! =)

So, I had some problem using it with Bower. It seems that its CSS isn't showed in the bower paths, then I can't use it properly with Gulp plugin main-bower-files.

Just to show the bower files, peform this command:

$ bower list --paths

It will show the following result:

'angular-ui-router-anim-in-out': 'bower_components/angular-ui-router-anim-in-out/anim-in-out.js'

It would be nice if it could return the following result:

'angular-ui-router-anim-in-out': ['bower_components/angular-ui-router-anim-in-out/anim-in-out.js', 'bower_components/angular-ui-router-anim-in-out/css/anim-in-out.css']

Thank you!

AnimOut not triggered in Angular v1.2.26

Hi,

Great directive!

I've run into a problem where 'animOut' is not triggered in my stateControllers. It does work with the angular version in this repo: v1.2.16, but it seems to be broken when working with v1.2.26. The 'animIn' is working in both versions though.

Can't figure out what seems to be the problem so far... Anybody has a fix for this?

Cheers!

Animations not trigerred in production env

Hi, Thanks for amazing plugin, works flawlessly. Unfortunatelly, my animations are not triggering on first initial load when app is compiled into one file. I've noticed that if app loads too fast then the animations are skipped. Do you have any ideas?

Event parameters in readme

Hi!

I'd like to thank you for this great module. Exactly what I needed, works like a charm! Just a small thing, in the Usage section of the readme, the event functions have two parameters (element and speed), for example:

$rootScope.$on('animStart', function(element, speed) {
    // do something
});

I found that it is not correct, I think there should be one more, probably the 'event' as first parameter.

Thanks again for the great work!

Usage Example

The project looks great but I have to dig through the code to figure out how to use it. Some basic usage / api would be great.

How can I troubleshoot animation issue?

I finally got around to implementing your work and having an issue in the animation. The loading view only uses half of the available screen and then expands to fill the screen. Doesn't look great. But how can I troubleshoot the issue? It's an angular app with jspm for package manager using babel for transpilation.

Possible to have the animation without absolute view?

Hi,

I am running into one issue where the absolute position of the ui-view that slides creates issues with the size of the parent element.
I have to set the absolute positioned element to a fixed height for it to work but that is causing issues because the view can grow (when form elements trigger errors, the error message slides out).
So I ideally I would work with a non fixed height but that conflicts with the absolute positioning.

Any suggestions?

Animation failed with error when debugInfoEnabled(false)

I want to prepare my app for production according to this doc: https://docs.angularjs.org/guide/production

But after this step

myApp.config(['$compileProvider', function ($compileProvider) {
  $compileProvider.debugInfoEnabled(false);
}]);

An anim-in-out.js will throw an error:

TypeError: Cannot read property '$broadcast' of undefined
    at Object.leave [as fn] (anim-in-out.js)
    at angular-animate.js:745
    at s (angular.js:323)
    at k (angular-animate.js:727)
    at Object.f.module.directive.factory.config.X.decorator.before (angular-animate.js:768)
    at G (angular-animate.js:1411)
    at angular-animate.js:1001
    at angular-animate.js:539
    at l.$get.l.$digest (angular.js:14293)
    at l.$get.l.$apply (angular.js:14506)
 (anonymous function)
$getangular.js
$get.l.$digestangular.js
$get.l.$applyangular.js
(anonymous function)

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.