ngx-free-fullpage
Version:
ngx-free-fullpage is a free-for-profit angular library that gives you all the tools you need to implement a fullpage scroll effect. This library hasn't been developed in order to substitute the current ngx-fullpage, this library is an alternative for thos
241 lines (225 loc) • 8.86 kB
JavaScript
import { __decorate } from 'tslib';
import { ɵɵdefineInjectable, Injectable, ElementRef, Directive, NgModule, Input } from '@angular/core';
let NgxFullpageService = class NgxFullpageService {
constructor() {
this.section = 0;
this.scrollHeight = 0;
this.goNext = () => (this.scroll(1));
this.goPrev = () => (this.scroll(-1));
this.goTo = (section) => (this.scroll(section - this.section));
this.adjustSection = (section) => this.setNumberInRange(section, 0, this.sectionsNumber - 1);
}
addWrapper(wrapper, section) {
if (this.wrapper)
throw new Error('There is already a wrapper defined');
this.wrapper = wrapper;
if (section > 0)
this.goTo(section);
}
scroll(direction) {
this.sectionsNumber = (this.wrapper.nativeElement.scrollHeight / this.wrapper.nativeElement.offsetHeight);
this.scrollHeight += direction * this.wrapper.nativeElement.offsetHeight;
this.scrollHeight = this.adjustScroll(this.scrollHeight);
this.wrapper.nativeElement.scroll({ top: this.scrollHeight });
this.section = this.adjustSection(Math.round(this.scrollHeight / this.wrapper.nativeElement.offsetHeight));
}
goLast() {
this.sectionsNumber = this.sectionsNumber || (this.wrapper.nativeElement.scrollHeight / this.wrapper.nativeElement.offsetHeight);
this.goTo(this.sectionsNumber - 1);
}
adjustScroll(scroll) {
let maxScroll = (this.sectionsNumber - 1) * this.wrapper.nativeElement.offsetHeight;
return this.setNumberInRange(scroll, 0, maxScroll);
}
setNumberInRange(n, min, max) {
return Math.min(Math.max(n, min), max);
}
};
NgxFullpageService.ɵprov = ɵɵdefineInjectable({ factory: function NgxFullpageService_Factory() { return new NgxFullpageService(); }, token: NgxFullpageService, providedIn: "root" });
NgxFullpageService = __decorate([
Injectable({
providedIn: 'root'
})
], NgxFullpageService);
let NgxFullpageGoToLastDirective = class NgxFullpageGoToLastDirective {
constructor(el, justFullpageService) {
this.el = el;
this.justFullpageService = justFullpageService;
this.el.nativeElement.onclick = (() => this.justFullpageService.goLast());
}
};
NgxFullpageGoToLastDirective.ctorParameters = () => [
{ type: ElementRef },
{ type: NgxFullpageService }
];
NgxFullpageGoToLastDirective = __decorate([
Directive({
selector: '[ngx-fullpage-go-to-last]'
})
], NgxFullpageGoToLastDirective);
let NgxFullpageGoToLastModule = class NgxFullpageGoToLastModule {
};
NgxFullpageGoToLastModule = __decorate([
NgModule({
declarations: [NgxFullpageGoToLastDirective],
imports: [],
exports: [NgxFullpageGoToLastDirective]
})
], NgxFullpageGoToLastModule);
let NgxFullpageWrapperDirective = class NgxFullpageWrapperDirective {
constructor(element, justFullpageService) {
this.element = element;
this.justFullpageService = justFullpageService;
this.section = 0;
this.delta = 0;
this.element.nativeElement.style['overflow'] = 'hidden';
this.element.nativeElement.style['scroll-behavior'] = "smooth";
this.element.nativeElement.onwheel = (ev) => this.wheelHandler(ev);
this.justFullpageService.addWrapper(element, this.section);
}
wheelHandler(event) {
this.delta += event.deltaY;
if (this.delta === event.deltaY)
setTimeout(() => {
let direction = Math.abs(this.delta) / this.delta;
this.justFullpageService.scroll(direction);
setTimeout(() => this.delta = 0, 150);
}, 50);
}
};
NgxFullpageWrapperDirective.ctorParameters = () => [
{ type: ElementRef },
{ type: NgxFullpageService }
];
__decorate([
Input()
], NgxFullpageWrapperDirective.prototype, "section", void 0);
NgxFullpageWrapperDirective = __decorate([
Directive({
selector: '[ngx-fullpage-wrapper]',
providers: [NgxFullpageService]
})
], NgxFullpageWrapperDirective);
let NgxFullpageSectionDirective = class NgxFullpageSectionDirective {
constructor(element) {
this.element = element;
this.element.nativeElement.style.height = "100%";
this.element.nativeElement.style.width = "100%";
}
};
NgxFullpageSectionDirective.ctorParameters = () => [
{ type: ElementRef }
];
NgxFullpageSectionDirective = __decorate([
Directive({
selector: '[ngx-fullpage-section]'
})
], NgxFullpageSectionDirective);
let NgxFullpageModule = class NgxFullpageModule {
};
NgxFullpageModule = __decorate([
NgModule({
declarations: [NgxFullpageWrapperDirective, NgxFullpageSectionDirective],
imports: [],
exports: [NgxFullpageWrapperDirective, NgxFullpageSectionDirective],
})
], NgxFullpageModule);
let NgxFullpageNextButtonDirective = class NgxFullpageNextButtonDirective {
constructor(el, justFullpageService) {
this.el = el;
this.justFullpageService = justFullpageService;
this.el.nativeElement.onclick = (_ev) => this.justFullpageService.goNext();
}
};
NgxFullpageNextButtonDirective.ctorParameters = () => [
{ type: ElementRef },
{ type: NgxFullpageService }
];
NgxFullpageNextButtonDirective = __decorate([
Directive({
selector: '[ngx-fullpage-next-button]'
})
], NgxFullpageNextButtonDirective);
let NgxFullpagePrevButtonDirective = class NgxFullpagePrevButtonDirective {
constructor(el, justFullpageService) {
this.el = el;
this.justFullpageService = justFullpageService;
this.el.nativeElement.onclick = (_ev) => this.justFullpageService.goPrev();
}
};
NgxFullpagePrevButtonDirective.ctorParameters = () => [
{ type: ElementRef },
{ type: NgxFullpageService }
];
NgxFullpagePrevButtonDirective = __decorate([
Directive({
selector: '[ngx-fullpage-prev-button]'
})
], NgxFullpagePrevButtonDirective);
let NgxFullpageNextButtonModule = class NgxFullpageNextButtonModule {
};
NgxFullpageNextButtonModule = __decorate([
NgModule({
declarations: [NgxFullpageNextButtonDirective, NgxFullpagePrevButtonDirective],
imports: [],
exports: [NgxFullpageNextButtonDirective, NgxFullpagePrevButtonDirective],
})
], NgxFullpageNextButtonModule);
let NgxFullpageToFirstButtonDirective = class NgxFullpageToFirstButtonDirective {
constructor(el, justFullpageService) {
this.el = el;
this.justFullpageService = justFullpageService;
this.el.nativeElement.onclick = (() => this.justFullpageService.goTo(0));
}
};
NgxFullpageToFirstButtonDirective.ctorParameters = () => [
{ type: ElementRef },
{ type: NgxFullpageService }
];
NgxFullpageToFirstButtonDirective = __decorate([
Directive({
selector: '[ngx-fullpage-go-to-first]'
})
], NgxFullpageToFirstButtonDirective);
let NgxFullpageToFirstButtonModule = class NgxFullpageToFirstButtonModule {
};
NgxFullpageToFirstButtonModule = __decorate([
NgModule({
declarations: [NgxFullpageToFirstButtonDirective],
imports: [],
exports: [NgxFullpageToFirstButtonDirective],
})
], NgxFullpageToFirstButtonModule);
let NgxFullpageGoToSectionDirective = class NgxFullpageGoToSectionDirective {
constructor(element, justFullpageService) {
this.element = element;
this.justFullpageService = justFullpageService;
this.element.nativeElement.onclick = () => this.justFullpageService.goTo(this.section);
}
};
NgxFullpageGoToSectionDirective.ctorParameters = () => [
{ type: ElementRef },
{ type: NgxFullpageService }
];
__decorate([
Input('ngx-fullpage-go-to-section')
], NgxFullpageGoToSectionDirective.prototype, "section", void 0);
NgxFullpageGoToSectionDirective = __decorate([
Directive({
selector: '[ngx-fullpage-go-to-section]'
})
], NgxFullpageGoToSectionDirective);
let NgxFullpageGoToSectionModule = class NgxFullpageGoToSectionModule {
};
NgxFullpageGoToSectionModule = __decorate([
NgModule({
declarations: [NgxFullpageGoToSectionDirective],
imports: [],
exports: [NgxFullpageGoToSectionDirective],
})
], NgxFullpageGoToSectionModule);
/**
* Generated bundle index. Do not edit.
*/
export { NgxFullpageGoToLastModule, NgxFullpageGoToSectionModule, NgxFullpageModule, NgxFullpageNextButtonModule, NgxFullpageService, NgxFullpageToFirstButtonModule, NgxFullpageGoToLastDirective as ɵa, NgxFullpageWrapperDirective as ɵb, NgxFullpageSectionDirective as ɵc, NgxFullpageNextButtonDirective as ɵd, NgxFullpagePrevButtonDirective as ɵe, NgxFullpageToFirstButtonDirective as ɵf, NgxFullpageGoToSectionDirective as ɵg };
//# sourceMappingURL=ngx-free-fullpage.js.map