Skip to content

Instantly share code, notes, and snippets.

@lasfrancisco
Created September 6, 2019 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lasfrancisco/331f12e48388ed202fb0347df7dec175 to your computer and use it in GitHub Desktop.
Save lasfrancisco/331f12e48388ed202fb0347df7dec175 to your computer and use it in GitHub Desktop.
Animate On Scroll - Component
@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