angular 4 programmatic animation -
how add animation programatically ?
@component({ moduleid: module.id, selector: 'my-toolbar', templateurl: './my-toolbar.component.html', styleurls: ['./my-toolbar.component.scss'], encapsulation: viewencapsulation.none, animations: [ trigger('mytoolbarstate', [ state('initial', style({top: '*'})), state('up', style({top: '-50px')), transition('initial => up, => initial', animate(header_shrink_transition)) ]) ] })
how achieve same without annotation ? underlying goal create dynamic trigger function uses different values based on @input
.
it important note animations or triggers must have at-least 1 variable. makes question different how reuse animations.
i ended following factory class shown below being used animations[]
:-
this used below:
@component({ selector: 'my-app-header', moduleid: module.id, templateurl: './app-header.component.html', styleurls: ['./app-header.component.scss'], animations: [ mytoolbaranimator.createtrigger('appheaderstate', '50px', '0') ] })
defined mytoolbaranimator
static method createtrigger
returns animationtriggermetadata
shown below
mytoolbaranimator
import {trigger, state, style, animate, transition, animationtriggermetadata} '@angular/animations'; export const header_shrink_transition = '250ms cubic-bezier(0.4,0.0,0.2,1)'; export class mytoolbaranimator { static createtrigger(triggername: string, initialtop: string, uptop: string): animationtriggermetadata { return trigger(triggername, [ state('initial', style({top: initialtop})), state('up', style({top: uptop})), transition('initial => up, => initial', animate(header_shrink_transition)) ]); } }
Comments
Post a Comment