chrisbateman / impetus

Agnostic utility for adding momentum to anything. It's like iScroll, except not for scrolling. Supports mouse and touch events.
chrisbateman.github.io/impetus
MIT License
487 stars 70 forks source link

How to judge whether the exercise has stopped #53

Open swimly opened 4 years ago

swimly commented 4 years ago

When I want to make a picker component, I want to adjust the displacement properly at the end of the movement. Is there any solution?

var max = this.$wrap.offsetHeight - this.itemHeight;
var offset = 0
new Impetus({
      source: this.el,
      boundY: [-max, 0],
      multiplier: 1,
      initialValues: [0, -this.current * this.itemHeight],
      update: (x, y) => {
        var dis = this.baseOffset() + y
        offset = this.getIndexByOffset(y)
        this.offset = dis
        this.$wrap.style.transform = `translate3d(0, ${dis}px, 0)`
      }
    })