mwg API
    Preparing search index...

    Class ScrollDrag

    Touch scrolling as plain numbers: feed it pointer positions and it says how far the content moves while the finger is down, then keeps coasting after release with a friction that decays the speed. No pointer events or clock of its own, so it is the same under a test as under a finger.

    import { ScrollDrag } from '@datamoc/mwg/two-d/ui';

    const drag = new ScrollDrag();
    drag.start(200, 0);
    console.log(drag.move(170, 0.1)); // 30: the content follows the finger up
    drag.end();
    console.log(drag.step(1 / 60) > 0); // true: it keeps coasting
    Index
    • Parameters

      • friction: number = 0.92

        fraction of the speed lost per second of coasting; 0.92 when omitted

      • minSpeed: number = 8

        the speed, in pixels per second, below which it counts as at rest; 8 when omitted

      Returns ScrollDrag

    dragging: boolean = false
    travelled: number = 0

    how far the pointer has travelled since start, to tell a drag from a tap

    velocity: number = 0

    content pixels per second the content keeps moving at after release; 0 when at rest

    • Parameters

      • y: number
      • time: number

      Returns number

      how far the content should move for this pointer position

    • Parameters

      • dt: number

      Returns number

      how far the content coasts in dt seconds, 0 once it has stopped