Guest User

Untitled

a guest
Feb 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. @Component({
  2. selector: 'slideIn',
  3. template: '<h1 [@scrollAnimation]="state">{{text}}</h1>',
  4. animations: [
  5. trigger('scrollAnimation', [
  6. state('show', style({
  7. transform: "translateX(0)"
  8. })),
  9. state('hide', style({
  10. transform: "translateX(-100%)"
  11. })),
  12. transition('show => hide', animate('1000ms')),
  13. transition('hide => show', animate('1000ms'))
  14. ])
  15. ]
  16. })
  17.  
  18. export class SlideComponent {
  19.  
  20. public state = 'hide';
  21.  
  22. @Input() text: String;
  23.  
  24. constructor(public el: ElementRef) {
  25. }
  26.  
  27. @HostListener('window:scroll', [])
  28. checkScroll() {
  29. var elementPosition = this.el.nativeElement.offsetTop
  30. var scrollPosition = window.pageYOffset
  31.  
  32. if (scrollPosition >= elementPosition) {
  33. this.state = 'show'
  34. } else {
  35. this.state = 'hide'
  36. }
  37. }
  38.  
  39. <slideIn text="Top Header"></slideIn>
  40. <slideIn text="Bottom Header"></slideIn>
Add Comment
Please, Sign In to add comment