npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng2-page-transition

v1.1.0

Published

Simple Angular2 component that creates a page transition animation on route changes

Downloads

125

Readme

Join the chat at https://gitter.im/bergben/bergben

ng2-page-transition

Simple Angular2 component to create a page transition animation on route changes.

Works for Angular 2.x only. Angular 4.1 will support route transitions built in, check out https://github.com/bergben/ng2-page-transition/issues/8

Features

All that this component does is listen for route changes and on NavigationStart it triggers an animation to fade out the current page and fade in the page on the new route. By default it also scrolls the page to the top on route changes, this can be disabled though.

Install

$ npm install ng2-page-transition --save

Add web-animations-js if you haven't done so already to support all browsers (see https://angular.io/docs/ts/latest/guide/animations.html)

$ npm install web-animations-js --save

Usage

Import the module

// app.module.ts
import {NgModule} from '@angular/core';
import { RouterModule } from '@angular/router'; //Router is required for the component to work
import {BrowserModule} from '@angular/platform-browser';
import { Ng2PageTransitionModule } from "ng2-page-transition"; // <-- import the module
import {MyComponent} from './my.component';

@NgModule({
    imports: [BrowserModule,
              RouterModule.forRoot() //Router is required
              Ng2PageTransitionModule // <-- include it in your app module
             ],
    declarations: [MyComponent],  
    bootstrap: [MyComponent]
})
export class MyAppModule {}

Wrap content in your template

<!-- my.component.html -->
<ng2-page-transition>
    <router-outlet></router-outlet>
    Some other content
</ng2-page-transition>

Options

scrollTop

By default the component scrolls to top on route changes, you can disable this by setting [scrollTop]="false"

<!-- my.component.html -->
<ng2-page-transition [scrollTop]="false">
    <router-outlet></router-outlet>
    Some other content
</ng2-page-transition>

onlyOnRoutes

By default the transition will take place on any route change. You can activate the transition only on routes that contain one or more certain strings:

<!-- my.component.html -->
<ng2-page-transition [onlyOnRoutes]="['blog']">
    <router-outlet></router-outlet>
    Some other content
</ng2-page-transition>

onlyOnRoutes takes an array of strings, in the example above the transition would only happen on any route containing "blog" in the url.

ignoreOnRoutes

By default the transition will take place on any route change. You can deactivate the transition for routes that contain one or more certain strings:

<!-- my.component.html -->
<ng2-page-transition [ignoreOnRoutes]="['blog']">
    <router-outlet></router-outlet>
    Some other content
</ng2-page-transition>

ignoreOnRoutes takes an array of strings, in the example above the transition wouldn't be triggered on any route containing "blog" in the url.

Custom transition

If you want a different animation than the default fade out and in then you can do that like so:

<!-- my.component.html -->
<ng2-page-transition [animation]="customAnimation">
    <div [@ng2ElementState]="customAnimation.state">
        Some other content
    </div>
</ng2-page-transition>
 //my.component.ts
 [...]
 import { customTransition } from './custom-transition.animation';

@Component({
  selector: 'my-component', 
  [...]
  animations: [customTransition()],
})
export class MyComponent {
  customAnimation:any = {custom:true, state:""};
}
 //custom-transition.animation.ts
import {trigger, state, animate, style, transition, AnimationEntryMetadata} from '@angular/core';

export function customTransition():AnimationEntryMetadata {
  return slideOutAndIn();
}

function slideOutAndIn():AnimationEntryMetadata {
  return trigger('ng2ElementState', [
    state('leave', style({
        position:'fixed', 
        width:'100%'
    })),
    state('enter', style({
        position:'fixed', 
        width:'100%'
    })),
    transition('* => enter', [
        style({transform: 'translateX(100%)'}),
        animate('0.5s ease-in-out', style({transform: 'translateX(0%)'}))
    ]),
    transition('* => leave', [
      style({transform: 'translateX(0%)'}),
      animate('0.5s ease-in-out', style({transform: 'translateX(-100%)'}))
    ]),
  ]);
}

customAnimation.state has three possible states: "enter", "leave" and "out". "out" is set on the router event NavigationEnd (see https://github.com/bergben/ng2-page-transition/blob/master/src/ng2-page-transition.component.ts#L36)

enterDelay

You can wait for the leaving animation to complete:

 //my.component.ts
 [...]
  customAnimation:any = {custom:true, state:"", enterDelay: 500};

In this case the entering animation would be delayed by 500 ms, allowing the leaving animation which takes 500ms to complete.

To-do

  • Provide a demo