Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module): compare position value to mapped offset value #64

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/app/+home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<button
(click)="show()"
[ngx-scroll-to-duration]="4000"
[ngx-scroll-to-duration]="1500"
[ngx-scroll-to]="'destination'"
[ngx-scroll-to-offset]="-10"
[ngx-scroll-to-offset-map]="offsetMap"
[ngx-scroll-to-easing]="'easeInOutQuint'"
>Go</button>
<section *ngIf="visible" id="destination">
You've reached your destination.
Expand Down
4 changes: 4 additions & 0 deletions src/app/+home/home.component.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
button {
margin-bottom: 100vh;
}

#destination {
margin-bottom: 200vh;
}
7 changes: 6 additions & 1 deletion src/app/+home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ import { Component, OnInit } from '@angular/core';
export class HomeComponent implements OnInit {

public visible = false;
public offsetMap;

constructor() { }
constructor() {
this.offsetMap = new Map();
this.offsetMap
.set(600, -500);
}

ngOnInit() {
}
Expand Down
16 changes: 11 additions & 5 deletions src/app/modules/scroll-to/statics/scroll-to-animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export class ScrollToAnimation {
*/
private _windowScrollTop: number;

/**
* Mapped Offset taken from the active Offset Map.
*/
private _mappedOffset: number;

/**
* Class Constructor.
*
Expand Down Expand Up @@ -90,17 +95,17 @@ export class ScrollToAnimation {
const directionalDistance = this._startPosition - this._to;
this._distance = Math.abs(this._startPosition - this._to);

let offset = this._options.offset;
this._mappedOffset = this._options.offset;

// Set offset from Offset Map
if (this._isBrowser) {

this._options
.offsetMap
.forEach((value, key) => offset = window.innerWidth > key ? value : offset);
.forEach((value, key) => this._mappedOffset = window.innerWidth > key ? value : this._mappedOffset);
}

this._distance += offset * (directionalDistance <= 0 ? 1 : -1);
this._distance += this._mappedOffset * (directionalDistance <= 0 ? 1 : -1);
this._source$ = new ReplaySubject();
}

Expand All @@ -121,6 +126,7 @@ export class ScrollToAnimation {
* @returns Void
*/
private _loop = (): void => {

this._timeLapsed += this._tick;
this._percentage = (this._timeLapsed / this._options.duration);
this._percentage = (this._percentage > 1) ? 1 : this._percentage;
Expand All @@ -147,8 +153,8 @@ export class ScrollToAnimation {
const currPosition = this._isWindow ? this._windowScrollTop : this._container.scrollTop;

if (force
|| Math.trunc(this._position) === (this._to + this._options.offset)
|| currPosition === (this._to + this._options.offset)) {
|| Math.trunc(this._position) === (this._to + this._mappedOffset)
|| currPosition === (this._to + this._mappedOffset)) {
clearInterval(this._interval);
this._interval = null;
this._source$.complete();
Expand Down