• Stars
    star
    234
  • Rank 171,630 (Top 4 %)
  • Language
    CSS
  • Created almost 11 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

More Repositories

1

angular-gsapify-router

Angular UI-Router animation directive allowing configuration of GSAP state transitions based on priority
JavaScript
85
star
2

angular-images-loaded

Super simple Angular directive to wrap imagesLoaded plugin
JavaScript
55
star
3

mjml-mailchimp

Mailchimp compatible MJML v4 components
JavaScript
50
star
4

angular-gridify

Angular directive that creates a justified grid of elements
HTML
29
star
5

scrollwizardry

ScrollMagic for wizards
JavaScript
24
star
6

angular-scroll-magic

An angular directive for ScrollMagic, define pins and tweens in markup
HTML
18
star
7

prisma2-example-yoga

Serverless prisma2 example with auth and subscriptions*
TypeScript
16
star
8

angular-scrollify

Angular directive that snaps to panes on scroll
CSS
12
star
9

angular-ui-sref-fastclick

Extends ui-sref directive (part of angular-ui-router) to add fastclick style behaviour
7
star
10

angular-cropify

Angular directive to crop/select an area of an element such as an image. Possible lightweight Jcrop alternative.
CSS
7
star
11

ace-cms

Flexible, multi-site, headless CMS
JavaScript
6
star
12

vuxtras

A collection of Nuxt compatible Vue components and plugins
Vue
6
star
13

git-sync-alternate

Shell
5
star
14

angular-columnify

Angular directive that creates balanced columns
CSS
5
star
15

angular-gridflex

Angular directive that creates a justified grid of elements using flexbox
CSS
5
star
16

ace-assist

Asset store with image/video processing and PDF generation
JavaScript
3
star
17

cloudant-backup

A utility for backing up your Cloudant databases without costly replication
JavaScript
2
star
18

infinite-highway

http://homerjam.github.io/infinite-highway/
JavaScript
2
star
19

youtube-iframe-api

YouTube iframe api for bower
2
star
20

showy

Ostentatious, canvas-based presentations
JavaScript
2
star
21

angular-sticky-container

Angular directive that provides 'sticky' functionality
JavaScript
2
star
22

prerender-s3-cache-alt

Prerender plugin for AWS S3 caching - optimised for human readability
JavaScript
2
star
23

genius

JavaScript
1
star
24

angular-modal-service2

Standalone AngularJS service for showing modals
CSS
1
star
25

smoothscroll

Native JS plugin to smooth scrolling with a mouse wheel
JavaScript
1
star
26

ace-api

Content API with included RESTish server
JavaScript
1
star
27

upload-test

JavaScript
1
star
28

angular-on-screen

Angular directive which checks if an element is within a certain range of viewport
JavaScript
1
star
29

nuxt-firebase-auth

TypeScript
1
star
30

smoothify

Scroll gracefully with your mousewheel
HTML
1
star
31

cloudant-restore

A utility for restoring your Cloudant databases without costly replication
JavaScript
1
star