【发布时间】:2019-03-18 12:03:20
【问题描述】:
我正在使用以下代码在 mouseDown 上滚动滚动元素,并在 mouseUp/mouseOut 上停止滚动。
scrubby(xDir) {
let dub = setInterval(() => {
document.getElementById("chart").scrollBy(8 * xDir, 0);
}, 10);
this.setState({ dub: dub });
}
scrubbyStop() {
const { dub } = this.state;
if (dub !== null) {
clearInterval(dub);
}
this.setState({ dub: null });
}
这适用于除 IE 11 之外的任何地方。在 IE 11 中,我收到以下错误:
TypeError: Object doesn't support property or method 'scrollBy'
当我 console.log 元素时,document.getElementById 以确保我选择了元素。
我正在使用 babel-polyfil
我看到很多与scrollTo相关的问题,但不是scrollBy。有谁知道任何可能适用于 IE 的解决方法、polyfill 或替代方法。
【问题讨论】:
标签: javascript reactjs internet-explorer-11 babel-polyfill