@hilux/ngx-motion 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/ngx-motion.directive.ts +21 -29
package/package.json
CHANGED
|
@@ -37,10 +37,10 @@ export class MotionDirective implements OnDestroy, AfterViewInit {
|
|
|
37
37
|
|
|
38
38
|
ngAfterViewInit() {
|
|
39
39
|
this.applyInitialStyles();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
this.runAnimation(this.onHover);
|
|
40
|
+
if (!this.variant) {
|
|
41
|
+
this.runAnimation(this.animate);
|
|
43
42
|
}
|
|
43
|
+
this.setupHoverAnimations();
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
ngOnDestroy() {
|
|
@@ -53,33 +53,14 @@ export class MotionDirective implements OnDestroy, AfterViewInit {
|
|
|
53
53
|
|
|
54
54
|
runAnimation(styles: any) {
|
|
55
55
|
let animationMetadata = [];
|
|
56
|
+
const currentStyles = this.variant === 'initial' ? this.initial :
|
|
57
|
+
this.variant === 'animate' ? this.animate :
|
|
58
|
+
this.variant === 'exit' ? this.exit : styles;
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
animate(`${this.duration} ${this.easing}`, style(this.animate)),
|
|
62
|
-
];
|
|
63
|
-
break;
|
|
64
|
-
case 'animate':
|
|
65
|
-
animationMetadata = [
|
|
66
|
-
style(this.initial),
|
|
67
|
-
animate(`${this.duration} ${this.easing}`, style(this.animate)),
|
|
68
|
-
];
|
|
69
|
-
break;
|
|
70
|
-
case 'exit':
|
|
71
|
-
animationMetadata = [
|
|
72
|
-
style(this.animate),
|
|
73
|
-
animate(`${this.duration} ${this.easing}`, style(this.exit)),
|
|
74
|
-
];
|
|
75
|
-
break;
|
|
76
|
-
default:
|
|
77
|
-
animationMetadata = [
|
|
78
|
-
style(this.initial),
|
|
79
|
-
animate(`${this.duration} ${this.easing}`, style(this.animate)),
|
|
80
|
-
];
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
60
|
+
animationMetadata = [
|
|
61
|
+
style(this.variant === 'initial' ? {} : this.initial),
|
|
62
|
+
animate(`${this.duration} ${this.easing}`, style(currentStyles))
|
|
63
|
+
];
|
|
83
64
|
|
|
84
65
|
const animation = this.builder.build(animationMetadata);
|
|
85
66
|
if (this.player) {
|
|
@@ -122,4 +103,15 @@ export class MotionDirective implements OnDestroy, AfterViewInit {
|
|
|
122
103
|
private applyInitialStyles() {
|
|
123
104
|
Object.assign(this.el.nativeElement.style, this.initial);
|
|
124
105
|
}
|
|
106
|
+
|
|
107
|
+
private setupHoverAnimations() {
|
|
108
|
+
if (this.onHover) {
|
|
109
|
+
this.el.nativeElement.addEventListener('mouseenter', () => {
|
|
110
|
+
this.runAnimation(this.onHover);
|
|
111
|
+
});
|
|
112
|
+
this.el.nativeElement.addEventListener('mouseleave', () => {
|
|
113
|
+
this.runAnimation(this.animate);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
125
117
|
}
|