Skip to content

Commit 05ae758

Browse files
committed
fix: 修复footer标签不能切换以及btn-click指令效果更改
1 parent 5476267 commit 05ae758

5 files changed

+28
-13
lines changed

src/app/edit/edit.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
</li>
5050
</ul>
5151
<div class="btn">
52-
<button type="submit" class="fl">保存</button>
52+
<button type="submit" class="fl" btnClickStyle>保存</button>
5353
<button (click)="cancleOperate()" class=" fr">取消</button>
5454
</div>
5555
</form>

src/app/shared/btn-click.directive.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
import {Directive, ElementRef, Input, Renderer} from "@angular/core";
22

3+
const ClickingBackColor = '#eee';
4+
35
@Directive({
46
selector: "[btnClickStyle]",
57
host: {
6-
"(click)": "btnClick()"
8+
"(click)": "doClick()"
79
}
810
})
911
export class BtnClickDirective {
1012
private el: HTMLElement;
13+
private timer: any;
14+
private animating: boolean;
1115
constructor(el: ElementRef) {
1216
this.el = el.nativeElement;
17+
this.el.style.transition = 'background-color .2s ease-out';
1318
}
14-
btnClick() {
15-
this._addClasssName("btn-click");
16-
}
17-
private _addClasssName(className: string) {
18-
this.el.className = this.el.className + " " + className;
19+
doClick() {
20+
if(this.animating) return;
21+
this.animating = true;
22+
this.el.prevBackColor = this.el.style.backgroundColor;
23+
this.el.style.backgroundColor = ClickingBackColor;
24+
clearTimeout(this.timer);
25+
this.timer = setTimeout(() => {
26+
this.el.style.backgroundColor = this.el.prevBackColor || '';
27+
this.animating = false;
28+
}, 200);
1929
}
2030
}
31+
32+
interface HTMLElement {
33+
prevBackColor: string;
34+
style: any;
35+
}

src/app/shared/footer.component.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ nav em {
4444
margin-top: -5px;
4545
opacity: 0;
4646
}
47-
nav a.btn-click em{
47+
/*nav a.btn-click em{
4848
-webkit-animation: scale_zoom 1s both infinite;
4949
}
5050
@@ -60,4 +60,4 @@ nav a.btn-click em{
6060
100%{
6161
opacity: 0;
6262
}
63-
}
63+
}*/

src/app/shared/footer.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<nav>
2-
<a [routerLink]=" ['/collection'] " [ngClass]="{clickOn: !footer}">
2+
<a [routerLink]=" ['/collection'] " [ngClass]="{clickOn: !isListPage}">
33
<i>收藏</i>
44
</a>
5-
<a [routerLink]=" ['/list']" [ngClass]="{clickOn: footer}" btnClickStyle>
5+
<a [routerLink]=" ['/list']" [ngClass]="{clickOn: isListPage}">
66
<em></em>
77
<i>通讯录</i>
88
</a>

src/app/shared/footer.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import {Location} from '@angular/common';
77
styleUrls: ['app/shared/footer.component.css']
88
})
99
export class FooterComponent implements OnInit {
10-
private footer:boolean = true;
10+
private isListPage:boolean = true;
1111

1212
constructor(
1313
private _location:Location
1414
) {}
1515

1616
ngOnInit() {
17-
this._location.path() == '' || this._location.path().indexOf('/contact-list') > -1 ? this.footer = true : this.footer = false;
17+
this.isListPage = this._location.path() == '' || this._location.path().indexOf('/list') > -1
1818
}
1919
}

0 commit comments

Comments
 (0)