my-lib/notice-bar/notice-bar.ts
encapsulation | ViewEncapsulation.None |
selector | notice-bar |
styleUrls | notice-bar.less, |
templateUrl | ./notice-bar.html |
Properties |
Methods |
Inputs |
Outputs |
constructor()
|
Defined in my-lib/notice-bar/notice-bar.ts:28
|
fps
|
Type:
Default value: |
Defined in my-lib/notice-bar/notice-bar.ts:21
|
model
|
Type: |
Defined in my-lib/notice-bar/notice-bar.ts:20
|
onAction
|
$event type: EventEmitter<any>
|
Defined in my-lib/notice-bar/notice-bar.ts:28
|
animation |
animation()
|
Defined in my-lib/notice-bar/notice-bar.ts:38
|
Returns :
void
|
doAction |
doAction()
|
Defined in my-lib/notice-bar/notice-bar.ts:52
|
Returns :
void
|
ngAfterViewInit |
ngAfterViewInit()
|
Defined in my-lib/notice-bar/notice-bar.ts:32
|
Returns :
void
|
action |
action:
|
Type : TemplateRef<any>
|
Decorators : ContentChild
|
Defined in my-lib/notice-bar/notice-bar.ts:17
|
icon |
icon:
|
Type : TemplateRef<any>
|
Decorators : ContentChild
|
Defined in my-lib/notice-bar/notice-bar.ts:18
|
marquee |
marquee:
|
Type : ElementRef
|
Decorators : ViewChild
|
Defined in my-lib/notice-bar/notice-bar.ts:25
|
maxWidth |
maxWidth:
|
Type : number
|
Default value : 0
|
Defined in my-lib/notice-bar/notice-bar.ts:26
|
noticeBarPrefixCls |
noticeBarPrefixCls:
|
Type : string
|
Default value : noticeBarPrefixCls
|
Defined in my-lib/notice-bar/notice-bar.ts:16
|
open |
open:
|
Type : boolean
|
Default value : true
|
Defined in my-lib/notice-bar/notice-bar.ts:22
|
right |
right:
|
Type : number
|
Default value : 0
|
Defined in my-lib/notice-bar/notice-bar.ts:23
|
timeLen |
timeLen:
|
Type : number
|
Default value : 0
|
Defined in my-lib/notice-bar/notice-bar.ts:27
|
import {
Component, OnInit, ViewEncapsulation,
HostBinding, Input, ContentChild, TemplateRef,
EventEmitter, Output, ViewChild, ElementRef, AfterViewInit
} from '@angular/core';
import { noticeBarPrefixCls } from './val';
import { ansycClassObj, merge, setClassObj, isMeepoTrue } from 'meepo-utils';
@Component({
selector: 'notice-bar',
templateUrl: './notice-bar.html',
styleUrls: ['./notice-bar.less', './patch.less'],
encapsulation: ViewEncapsulation.None
})
export class NoticeBarComponent implements AfterViewInit {
noticeBarPrefixCls: string = noticeBarPrefixCls;
@ContentChild('action') action: TemplateRef<any>;
@ContentChild('icon') icon: TemplateRef<any>;
@Input() model: 'closeable' | 'link';
@Input() fps: number = 40;
open: boolean = true;
right: number = 0;
@ViewChild('marquee') marquee: ElementRef;
maxWidth: number = 0;
timeLen: number = 0;
@Output() onAction: EventEmitter<any> = new EventEmitter();
constructor() { }
ngAfterViewInit() {
this.maxWidth = this.marquee.nativeElement.clientWidth - this.marquee.nativeElement.parentElement.clientWidth + 5;
this.timeLen = 1 / this.fps! * 1000;
this.animation();
}
animation() {
setTimeout(() => {
if (this.right < this.maxWidth) {
this.right++;
this.animation();
} else {
setTimeout(() => {
this.right = 0;
this.animation();
}, this.timeLen * 80);
}
}, this.timeLen);
}
doAction() {
if (this.model === 'closeable') {
this.open = false;
}
this.onAction.emit();
}
}
<div class="am-notice-bar" *ngIf="open" role="alert">
<div class="am-notice-bar-icon" *ngIf="icon">
<ng-container *ngTemplateOutlet="icon"></ng-container>
</div>
<div class="am-notice-bar-content">
<div class="am-notice-bar-marquee-wrap " role="marquee" style="overflow: hidden;">
<div class="am-notice-bar-marquee" #marquee [style.right.px]="right">
<ng-content></ng-content>
</div>
</div>
</div>
<div class="am-notice-bar-operation" (click)="doAction()" aria-label="close" role="button" *ngIf="action">
<ng-container *ngTemplateOutlet="action"></ng-container>
</div>
</div>