项目作者: haoliangwu

项目描述 :
angular 4+ custom anchor components
高级语言: TypeScript
项目地址: git://github.com/haoliangwu/ngx-anchor.git
创建时间: 2018-01-25T02:06:51Z
项目社区:https://github.com/haoliangwu/ngx-anchor

开源协议:

下载


ngx-anchor

angular 4+ custom anchor components. DEMO

todos

  • custom anchor mark directive
  • build-in anchor navigator
  • mult anchor level support
  • custom animation options
  • ember layout support
  • public navigator service

installing and usage

npm install ngx-anchor --save

load module in app module (with or without global configuration)

  1. // without configuration
  2. imports: [
  3. ...
  4. NgxAnchorModule.forRoot(),
  5. ...
  6. ]
  7. // with configuration
  8. imports: [
  9. ...
  10. NgxAnchorModule.forRoot({
  11. duration: 1000,
  12. step: 10,
  13. sensitivity: 36
  14. }),
  15. ...
  16. ]

configuration

  • duration(number): scroll animation total duration distance
  • step(number): the step per requestAnimationFrame
  • sensitivity(number): the offset which affects anchor navigator auto-active when trigger scroll events, default is 12px
  • timeFunc: scroll animation time function used, signature is
    1. funciton timeFunc(step: number, start: number, change: number, duration: number) => number

directives

ngxAnchor

custom anchor mark

  • ngxAnchor(string): anchor custom id

example:

  1. <h1 [ngxAnchor]="foo">main title{{foo}}</h1>

ngxWithAnchor

parent anchor mark

  • ngxWithAnchor(string): parent anchor id

example:

  1. <h1 [ngxAnchor]="foo" [header]="true">main title{{foo}}</h1>
  2. <section [ngxWithAnchor]="foo">
  3. <h2 [ngxAnchor]="bar">sub main title{{bar}}</h2>
  4. </section>

components

ngx-anchor-nav

build-in anchor navigator

  • anchorTpl(TemplateRef)

example:

  1. <ngx-anchor-nav>
  2. <ng-template #anchorTpl let-index="id">
  3. <span>{{index}}</span>
  4. </ng-template>
  5. </ngx-anchor-nav>

services

AnchorService

property

  • anchors( { [id: string]: anchor: Anchor} ): all regisitry custom anchor instance
  • activeAnchor(Anchor): current active anchor instance
  • scrollEvents(Observable): current active anchor Observable

method

  1. anchorFactory(el: HTMLElement, constraint: AnchorRelConstriant): Anchor

anchor instance factory with el

  1. get(id: string): Anchor

retrive anchor instance by id

  1. register(el: HTMLElement, constraint: AnchorRelConstriant)

register el as anchor instance

  1. scrollTo(anchor: Anchor | string, scrollOptions?: AnchorScrollConfig)

scroll to some anchor instance with custom animation options

  1. attachListner(el: HTMLElement | Window = window): Observable<Anchor>

attach scroll listner to container element, default is window