Created
September 6, 2019 14:59
-
-
Save lasfrancisco/331f12e48388ed202fb0347df7dec175 to your computer and use it in GitHub Desktop.
Animate On Scroll - Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: '[wmAnimate]', | |
template: '<ng-content></ng-content>', | |
animations: $animations | |
}) | |
export class AnimateComponent implements OnInit, OnDestroy { | |
readonly timings = { slower: '3s', slow: '2s', normal: '1s', fast: '500ms', faster: '300ms' }; | |
constructor(private elm: ElementRef, private scroll: ScrollDispatcher, private zone: NgZone) {} | |
/** Selects the animation to be played */ | |
@Input('wmAnimate') animate: wmAnimations; | |
/** Speeds up or slows down the animation */ | |
@Input() speed: wmAnimateSpeed = 'normal'; | |
/** When true, triggers the animation on element scrolling in the viewport */ | |
@Input('aos') set enableAOS(value: boolean) { this.aos = coerceBooleanProperty(value); } | |
public aos: boolean = false; | |
/** Specifies the amout of visibility triggering AOS */ | |
@Input() threshold: number = 0.2; | |
ngOnInit() { | |
// Triggers the animation based on the input flags | |
this.animateTrigger(this.elm).subscribe( trigger => { | |
// Triggers the animation to play or to idle | |
this.trigger = trigger ? this.play : this.idle; | |
}); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment