File

my-lib/notice-bar/notice-bar.ts

Implements

AfterViewInit

Metadata

encapsulation ViewEncapsulation.None
selector notice-bar
styleUrls notice-bar.less,
patch.less
templateUrl ./notice-bar.html

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor()

Inputs

fps

Type: number

Default value: 40

model

Type: "closeable" | "link"

Outputs

onAction $event type: EventEmitter<any>

Methods

animation
animation()
Returns : void
doAction
doAction()
Returns : void
ngAfterViewInit
ngAfterViewInit()
Returns : void

Properties

action
action: TemplateRef<any>
Type : TemplateRef<any>
Decorators : ContentChild
icon
icon: TemplateRef<any>
Type : TemplateRef<any>
Decorators : ContentChild
marquee
marquee: ElementRef
Type : ElementRef
Decorators : ViewChild
maxWidth
maxWidth: number
Type : number
Default value : 0
noticeBarPrefixCls
noticeBarPrefixCls: string
Type : string
Default value : noticeBarPrefixCls
open
open: boolean
Type : boolean
Default value : true
right
right: number
Type : number
Default value : 0
timeLen
timeLen: number
Type : number
Default value : 0
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>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""