@@ -17,9 +17,9 @@ import * as classes from './classes';
1717 * that detects scroll direction and adds a `sn-scrolling-up` or
1818 * `sn-scrolling-down` class to the element. The library can also detect when
1919 * the user has scrolled passed the element and apply a `sn-affix` class.
20- * Useful for make a element sticky when the user has scrolled beyond it. This
21- * library can will also apply `sn-minimize` class after the user has scrolled
22- * beyond the height of the element.
20+ * Useful for make a element sticky when the user has scrolled beyond it.
21+ * This library can will also apply `sn-minimize` class after the user has
22+ * scrolled beyond the height of the element.
2323 *
2424 * @example
2525 * ```
@@ -89,6 +89,15 @@ export class ScrollCollapseDirective implements OnInit, OnDestroy {
8989 public get isScrollingDown ( ) : boolean {
9090 return this . scrollDirection === Direction . DOWN ;
9191 }
92+ /**
93+ * Returns true if the user has scrolled pass the origin height of
94+ * the element assuming the element is fixed at the top of the page
95+ *
96+ * @type {boolean }
97+ * @memberof ScrollCollapseDirective
98+ */
99+ @HostBinding ( classes . minimiseClass )
100+ public minimiseMode = false ;
92101 /**
93102 * Creates an instance of ScrollCollapseDirective.
94103 * @param {ElementRef } el
@@ -106,7 +115,10 @@ export class ScrollCollapseDirective implements OnInit, OnDestroy {
106115 . takeUntil ( this . ngUnsubscribe$ )
107116 . debounceTime ( this . debounce )
108117 . bufferCount ( 2 , 1 )
109- . subscribe ( ( events : Viewport [ ] ) => this . calculateScrollDirection ( events ) ) ;
118+ . subscribe ( ( events : Viewport [ ] ) => {
119+ this . calculateScrollDirection ( events ) ;
120+ this . calculateMinimiseMode ( events [ 1 ] ) ;
121+ } ) ;
110122 }
111123 /**
112124 * On window scroll/resize/load events
@@ -131,10 +143,10 @@ export class ScrollCollapseDirective implements OnInit, OnDestroy {
131143 this . viewport$ . next ( viewport ) ;
132144 }
133145 /**
134- * Calculate scrollCollapse status and emit event
135- * when viewport status has changed
146+ * Calculate last scroll direction by comparing y scroll position
147+ * of last two values of `viewport$` observable
136148 *
137- * @param {Viewport } viewport
149+ * @param {Viewport[] } events
138150 * @memberof ScrollCollapseDirective
139151 */
140152 public calculateScrollDirection ( events : Viewport [ ] ) : void {
@@ -143,6 +155,17 @@ export class ScrollCollapseDirective implements OnInit, OnDestroy {
143155 this . scrollDirection = ( pastEvent . scrollY > currentEvent . scrollY ) ?
144156 Direction . UP : Direction . DOWN ;
145157 }
158+ /**
159+ * Calculate if the user has scrolled pass the origin height of
160+ * the element assuming the element is fixed at the top of the page
161+ *
162+ * @param {Viewport } viewport
163+ * @memberof ScrollCollapseDirective
164+ */
165+ public calculateMinimiseMode ( viewport : Viewport ) : void {
166+ const el : HTMLElement = this . el . nativeElement ;
167+ this . minimiseMode = viewport . scrollY > el . offsetHeight ;
168+ }
146169 /**
147170 * trigger `ngUnsubscribe` complete on
148171 * component destroy lifecycle hook
0 commit comments