我遵循documentation来实现react-custom-scrollbar的SpringScollbars。 SpringScrollbars代码中有一个导入
import { SpringSystem, MathUtil } from 'rebound';
在这一行中,SpringSystem已正确导入,但MathUtil未正确导入。我怀疑由于这个问题,只有我的代码无法正常工作
在上图中,可以看出MathUtil没有被导入。有什么解决办法吗?
这是SpringScrollbars.js的代码
SpringScrollbars.js
import React, { Component } from 'react';
import { Scrollbars } from 'react-custom-scrollbars';
import { SpringSystem, MathUtil } from 'rebound';
export default class SpringScrollbars extends Component {
constructor(props, ...rest) {
super(props, ...rest);
this.handleSpringUpdate = this.handleSpringUpdate.bind(this);
}
componentDidMount() {
this.springSystem = new SpringSystem();
this.spring = this.springSystem.createSpring();
this.spring.addListener({ onSpringUpdate: this.handleSpringUpdate });
}
componentWillUnmount() {
this.springSystem.deregisterSpring(this.spring);
this.springSystem.removeAllListeners();
this.springSystem = undefined;
this.spring.destroy();
this.spring = undefined;
}
getScrollTop() {
return this.refs.scrollbars.getScrollTop();
}
getScrollHeight() {
return this.refs.scrollbars.getScrollHeight();
}
getHeight() {
return this.refs.scrollbars.getHeight();
}
scrollTop(top) {
const { scrollbars } = this.refs;
const scrollTop = scrollbars.getScrollTop();
const scrollHeight = scrollbars.getScrollHeight();
const val = MathUtil.mapValueInRange(top, 0, scrollHeight, scrollHeight * 0.2, scrollHeight * 0.8);
this.spring.setCurrentValue(scrollTop).setAtRest();
this.spring.setEndValue(val);
}
handleSpringUpdate(spring) {
const { scrollbars } = this.refs;
const val = spring.getCurrentValue();
scrollbars.scrollTop(val);
}
render() {
return (
<Scrollbars
{...this.props}
ref="scrollbars"/>
);
}
}