zscroller
dom scroller based on zynga scroller
Last updated 7 years ago by yiminghe .
MIT · Repository · Bugs · Original npm
$ cnpm install zscroller 
SYNC missed versions from official npm registry.

zscroller


dom scroller based on zynga scroller

NPM version gemnasium deps node version npm download

Example

http://localhost:6006/examples/

online example: http://yiminghe.github.io/zscroller/

install

zscroller

API

typed

interface ViewportSize {
    width: number;
    height: number;
}
interface ContentSize {
    width: number;
    height: number;
}
interface X {
    // scrollbar x size
    width: number;
    height?: number;
    scrollbar?: {
        style: any;
    };
    indicator?: {
        style: any;
    };
}
interface Y {
    width?: number;
     // scrollbar y height
    height: number;
    scrollbar?: {
        style: any;
    };
    indicator?: {
        style: any;
    };
}
interface ZScrollerOption {
    locking?: boolean;
    viewport: ViewportSize;
    content: ContentSize;
    x?: X;
    y?: Y;
    container?: HTMLElement;
    scrollingComplete?: () => any;
    onScroll?: (left: number, top: number, zoom: number) => any;
}
declare class ZScroller {
    constructor(_options: ZScrollerOption);
    scrollTo(x: number, y: number, animate: boolean): void;
    scrollBy(x: number, y: number, animate: boolean): void;
    getScrollbar(type: any): HTMLElement;
    getScrollPosition(): {left:number;top:number;};
    setDisabled(disabled: any): void;
    // relayout
    setDimensions({ viewport, content, x, y, }?: {
        viewport?: ViewportSize;
        content?: ContentSize;
        x?: X;
        y?: Y;
    }): void;
    destroy(): void;
}

usage

import ZScroller from 'zscroller';

const zscroller = new ZScroller({
    container: container,
    viewport: {
      height: container.clientHeight - 20, // padding
      width: container.clientWidth - 20,
    },
    content: {
      width: content.offsetWidth,
      height: content.offsetHeight
    },
    x: {
      width: container.current.clientWidth - 4, // padding

    },
    y: {
      height: container.current.clientHeight - 4, // padding
    },
    onScroll(left, top) {
      content.style.transform = `translate3d(${-left}px,${-top}px,0)`
      content.style.webkitTransform = `translate3d(${-left}px,${-top}px,0)`;
    }
  });
container.appendChild(zscroller.getScrollbar('x'));
container.appendChild(zscroller.getScrollbar('y'));

License

zscroller is released under the MIT license.

Current Tags

  • 0.7.1                                ...           latest (5 years ago)

4 Versions

  • 0.7.1                                ...           5 years ago
  • 0.2.5                                ...           9 years ago
  • 0.3.1                                ...           8 years ago
  • 0.4.8                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org