Package detail

zscroller

yiminghe88.5kMIT0.7.1

dom scroller based on zynga scroller

zynga scroller, dom scroller

readme

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;
    };
}

//  minZoom defaults to 0.1
//  maxZoom defaults to 10
// locking defaults to true
//  defaultScrollX defaults to 0
//  defaultScrollY defaults to 0
//  defaultZoom defaults to 1
interface IZScrollerOption {
  minZoom?: number;
  maxZoom?: number;
  minIndicatorSize?: number;
  zooming?: boolean;
  locking?: boolean;
  viewport: IViewportSize;
  content: IContentSize;
  x?: X;
  y?: Y;
  defaultScrollX?:number;
  defaultScrollY?:number;
  defaultZoom?:number;
  container?: HTMLElement;
  scrollingComplete?: () => any;
  onScroll?: (x: number, y: 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(): {x:number;y: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.

changelog

History


0.7.0 / 2020-10-26

  • support defaultScrollX, defaultScrollY, defaultZoom

0.6.0 / 2020-02-20

  • unify pc and mobile interaction

0.4.0 / 2017-10-07

  • use lightweight raf and passive event

0.3.0 / 2017-05-23

  • locking change to radian check. 45deg

0.2.0 / 2016-09-10

  • support scrollbars options