|
1 |
| -import { Directive, ElementRef, HostListener } from '@angular/core'; |
| 1 | +import { Directive, ElementRef, HostListener, input } from '@angular/core'; |
2 | 2 |
|
3 | 3 | @Directive({
|
4 |
| - selector: '[llImagePreview]', |
| 4 | + selector: 'img[llImagePreview]', |
5 | 5 | })
|
6 | 6 | export class ImagePreviewDirective {
|
7 |
| - constructor(private hostElement: ElementRef<HTMLImageElement>) { |
8 |
| - console.log('ImagePreviewDirective', hostElement.nativeElement); |
| 7 | + scale = input<number>(2, { alias: 'llImagePreview' }); |
| 8 | + |
| 9 | + constructor(private hostElement: ElementRef<HTMLImageElement>) {} |
| 10 | + |
| 11 | + @HostListener('mouseover') |
| 12 | + public onMouseOver() { |
| 13 | + if (this.hostElement.nativeElement.parentElement) { |
| 14 | + this.hostElement.nativeElement.parentElement.style.overflow = 'visible'; |
| 15 | + } |
| 16 | + this.hostElement.nativeElement.style.zIndex = '50'; |
| 17 | + this.hostElement.nativeElement.style.transform = `scale(${this.scale() || 2})`; |
| 18 | + this.hostElement.nativeElement.style.transition = 'transform 0.3s ease-in-out'; |
9 | 19 | }
|
10 | 20 |
|
11 |
| - @HostListener('mouseover', ['$event']) |
12 |
| - public onMouseOver(event: MouseEvent) { |
13 |
| - const img = event.target as HTMLImageElement; |
14 |
| - console.log('mouseover', event); |
15 |
| - console.log('mouseover', img.srcset); |
| 21 | + @HostListener('mouseout') |
| 22 | + public onMouseOut() { |
| 23 | + this.hostElement.nativeElement.style.transform = 'scale(1)'; |
| 24 | + this.hostElement.nativeElement.style.zIndex = ''; |
| 25 | + setTimeout(() => { |
| 26 | + if (this.hostElement.nativeElement.parentElement) { |
| 27 | + this.hostElement.nativeElement.style.transform = ''; |
| 28 | + this.hostElement.nativeElement.style.transition = ''; |
| 29 | + this.hostElement.nativeElement.parentElement.style.overflow = ''; |
| 30 | + } |
| 31 | + }, 400); |
16 | 32 | }
|
17 | 33 | }
|
0 commit comments