0

I need to make a repeatable animation when hover a link.

I've made a route link component which contains that animation:

import { Component, Input, OnInit, trigger, state, style, transition, animate } from '@angular/core';

@Component({
  moduleId: module.id,
  selector: 'routelink',
  template: `<a [@hoverState]="isHover" (mouseenter)="mouseEnter()"  (mouseleave)="mouseLeave()" routerLink="{{routerLink}}" routerLinkActive="active">{{title}}</a>`,
  styleUrls: [ 'routelink.component.css' ],
  animations : [
    trigger('hoverState', [
      state('false', style({
        transform: 'scale(1)'
      })),
      state('true',   style({
        transform: 'scale(1.5)'
      })),
      transition('false <=> true', animate('1000ms ease-in-out'))
    ])
  ]
})

export class RouteLinkComponent { 
  @Input()
  title : String;

  @Input()
  routerLink : String;

  isHover : String;

  ngOnInit(): void {
    this.isHover = "false";
  }

  mouseEnter() {
      this.isHover = "true"; 
  }

  mouseLeave() {
      this.isHover = "false"; 
  }
}

After hovering the link - it scales as expected but stops when it reaches maximum size. As you can see I used ease-in-out in that animation. What am I missing here ?

UPDATE:

I've created a plunker for this question: https://plnkr.co/edit/e7sN2Aoz2sr68CrWxtgo?p=preview

br.julien
  • 3,420
  • 2
  • 23
  • 44
ohadinho
  • 6,894
  • 16
  • 71
  • 124

1 Answers1

0

Simple css animation is enough.

Working plunker.

kind user
  • 40,029
  • 7
  • 67
  • 77