Skip to content

Commit

Permalink
feat(scroll directive): add yOffset input to class setting functions
Browse files Browse the repository at this point in the history
apply classes on scroll taking into account yOffset property
  • Loading branch information
jackhkmatthews committed Jun 5, 2018
1 parent dd94f37 commit 1336f0b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ <h1>Scroll down ↓</h1>
</div>

<div class="spacer"></div>

<!-- nested element -->
<div class="bar-container">
<div class="bar bar--offset" [yOffset]="200" snScrollCollapse>
Classes applied when original Y position of element approaches yOffset. [yOffset]="200"
</div>
</div>

<div class="spacer"></div>
9 changes: 9 additions & 0 deletions src/app/app.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
z-index: 9999;
}

.bar.bar--offset.sn-affix {
top: 100px;
}

.bar.bar--offset.sn-minimise {
background-color: #586e5d;
height: 50px;
}

.spacer {
height: 150vh;
}
Expand Down
15 changes: 13 additions & 2 deletions src/app/scroll-collapse/scroll-collapse.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ export class ScrollCollapseDirective implements AfterViewInit, OnDestroy {
* @memberof ScrollCollapseDirective
*/
@Input() public debounce = 0;
/**
* Number of pixels before the elements originalTop
* position is scroll to that the classes will be applied.
* This value will need to take into account elements which become
* fixed above this element while scrolling as they reduce
* the height of the document and the scrollY number.
*
* @default 0
* @memberof ScrollCollapseDirective
*/
@Input() public yOffset = 0;
/**
* Returns true if last scroll direction is UP
*
Expand Down Expand Up @@ -190,7 +201,7 @@ export class ScrollCollapseDirective implements AfterViewInit, OnDestroy {
*/
public calculateMinimiseMode(viewport: Viewport): void {
this.minimiseMode =
viewport.scrollY >= this.originalHeight + this.originalTop;
viewport.scrollY >= this.originalHeight + this.originalTop - this.yOffset;
}
/**
* Calculate if the user has scrolled pass the origin height of
Expand All @@ -199,7 +210,7 @@ export class ScrollCollapseDirective implements AfterViewInit, OnDestroy {
* @memberof ScrollCollapseDirective
*/
public calculateAffixMode(viewport: Viewport): void {
this.affixMode = viewport.scrollY >= this.originalTop;
this.affixMode = viewport.scrollY >= this.originalTop - this.yOffset;
}
/**
* Return current viewport values
Expand Down

0 comments on commit 1336f0b

Please sign in to comment.