我正在使用以下代码在 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'
当我控制台记录元素时,document.getElementById 确保我选择了元素。
我正在使用 babel-polyfil
我看到很多问题与scrollTo有关,但与scrollBy无关。有谁知道任何可能适用于 IE 的解决方法、polyfill 或替代方案。
最佳答案
Babel polyfill “将模拟完整的 ES2015+ 环境”。然而,scrollBy
不是 ECMAScript 规范的一部分,因此不会被 Babel 填充。
你需要自己添加合适的polyfill,比如smooth scroll behaviour polyfill其中还包括 scrollBy
。
关于javascript - 对象在 React 的 IE11 中不支持属性或方法 'scrollBy',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52793371/