tangdaohai/vue-happy-scroll

如何监听滚动条事件?

Closed this issue · 1 comments

如何监听滚动条事件?

请看源码:

// 鼠标拖动滚动条时,移动slot元素到对应位置
watch:{
  slideX: function slideX(newVal) {
    this.$refs.container.scrollLeft = newVal / this.percentageX;
    this.$emit('update:scrollLeft', this.$refs.container.scrollLeft);
  },
  slideY: function slideY(newVal) {
    this.$refs.container.scrollTop = newVal / this.percentageY;
    // this.$refs.container.scrollTop 会在渲染之后被自动调整,所以这里重新取值
    this.$emit('update:scrollTop', this.$refs.container.scrollTop);
  }
}