Change pageTop bg onScroll.

This commit is contained in:
smartapant 2016-04-27 18:21:52 +03:00
parent 0b399a4a1b
commit d5dab605a9
4 changed files with 34 additions and 3 deletions

View file

@ -0,0 +1 @@
export * from './scrollPosition.directive';

View file

@ -0,0 +1,23 @@
import {Directive, Input, Output, EventEmitter, HostListener, ElementRef} from 'angular2/core';
@Directive({
selector: '[scrollPosition]'
})
export class ScrollPosition {
@Input() maxHeight: Number;
@Output() scrollChange:EventEmitter<Boolean> = new EventEmitter<Boolean>();
private _isScrolled: Boolean;
ngOnInit() {
this.onWindowScroll();
}
@HostListener('window:scroll')
onWindowScroll() : void {
let isScrolled = window.scrollY > this.maxHeight;
if (isScrolled !== this._isScrolled) {
this._isScrolled = isScrolled;
this.scrollChange.emit(isScrolled);
}
}
}

View file

@ -2,12 +2,19 @@ import {Component, ViewEncapsulation} from 'angular2/core';
import {MsgCenter} from '../msgCenter'; import {MsgCenter} from '../msgCenter';
import {ProfilePicturePipe} from '../pipes/image/profile-picture.pipe'; import {ProfilePicturePipe} from '../pipes/image/profile-picture.pipe';
import {ScrollPosition} from '../directives/scrollPosition.directive';
@Component({ @Component({
selector: 'page-top', selector: 'page-top',
styles: [ require('./pageTop.scss') ], styles: [ require('./pageTop.scss') ],
template: require('./pageTop.html'), template: require('./pageTop.html'),
directives: [MsgCenter], directives: [MsgCenter, ScrollPosition],
pipes: [ProfilePicturePipe] pipes: [ProfilePicturePipe]
}) })
export class PageTop {} export class PageTop {
isScrolled: Boolean = false;
scrolledChanged(isScrolled) {
this.isScrolled = isScrolled;
}
}

View file

@ -1,4 +1,4 @@
<div class="page-top clearfix" scroll-position="scrolled" max-height="50" ng-class="{'scrolled': scrolled}"> <div class="page-top clearfix" scrollPosition maxHeight="50" (scrollChange)="scrolledChanged($event)" [ngClass]="{scrolled: isScrolled}">
<a href="#/dashboard" class="al-logo clearfix"><span>Blur</span>Admin</a> <a href="#/dashboard" class="al-logo clearfix"><span>Blur</span>Admin</a>
<a href class="collapse-menu-link ion-navicon" ng-click="isMenuCollapsed=!isMenuCollapsed"></a> <a href class="collapse-menu-link ion-navicon" ng-click="isMenuCollapsed=!isMenuCollapsed"></a>