我在方法中使用滚动
const scrollToCenter = () => {
const kon = document.querySelector('.clazz');
const width = kon.offsetWidth;
kon.scrollTo(width / 2, 0);
};
,它可以在Chrome和Mozilla中正常运行。在Edge中,我收到一个错误“对象不支持属性或方法scrollTo”。 在Edge中有使用它的其他方法吗?
答案 0 :(得分:8)
官方报告: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/15534521/
问题已分配给某人。
在评论之后,解决方法是
”
.scrollTop = 0
而非.scrollTo(0,0)
,如果您想滚动到顶部以外的其他地方,我还没有找到解决方法“
答案 1 :(得分:0)
我在scrollIntoView上进行了更改-首先,它可以正常工作,并且应用程序不会中断。我将在其他浏览器上进行测试,如果它可以正常运行,那么这将是我的问题的解决方案。
k-nut的答案是正确的。