1.0.0 • Published 12 months ago

@kovalenko/scroll-here v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

ScrollHere

Scrolls specified container to the element with this directive when it's condition becomes truthy.

Installation

npm install @kovalenko/scroll-here

Supported API

Properties

@Input()TypeRequiredDefaultDescription
ngcScrollHerebooleanrequiredSets condition when to start scrolling
ngcScrollContainerstring / HTMLElementoptional'html'Place this attribute BEFORE ngcScrollHere in template. Should get a html element or css selector for a scrollable element; window will be used if this attribute is empty
ngcScrollDurationnumberoptional200Sets the scroll duration

Events

@Output()TypeEvent TypeRequiredDescription
ngcScrollTriggeredEventEmittervoidoptionalthis will callback if start scrolling condition has been met
ngcScrollFinishedEventEmittervoidoptionalthis will callback if scrolling has been finished

Usage

First, import the ScrollHereModule to your module:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ScrollHereModule } from '@kovalenko/scroll-here';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppComponent } from './app';

@NgModule({
  imports: [BrowserModule, ScrollHereModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

platformBrowserDynamic().bootstrapModule(AppModule);

In this example, window will be scrolled to inner div and when ngcScrollFinished callback will be invoked the window will be scrolled to outer div

import { Component } from '@angular/core';

@Component({
  selector: 'app',
  template: `
    <div style="padding-top: 3000px" [ngcScrollHere]="toTop" [ngcScrollDuration]="4000">
      <div [ngcScrollHere]="!triggered && s" [ngcScrollDuration]="2000" (ngcScrollTriggered)="triggered = true" (ngcScrollFinished)="toTop = true">Bottom</div>
    </div>
  `,
})
export class AppComponent {
  s = true;
  triggered = false;
  toTop = false;
}

License

MIT

1.0.0

12 months ago

0.0.7

2 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago