scrollIntoView 在 safari 浏览器中没有按预期工作 [英] scrollIntoView is not working as expected in safari browser
问题描述
我有这个可滚动的 div,在里面我有一个带有 id 点的 SVG.我想将选定的点与 div 的中心对齐,我有这个解决方案
I have this scrollable div and inside i have an SVG with points that has id's given. i want to align the selected point to the centre of the div and i have this solution
document.getElementById("myID").scrollIntoView({
behavior: 'smooth',
block: 'nearest',
inline: 'center'
})
这在 chrome 中运行良好,但在 safari 中不起作用,最佳解决方案是什么?
this works fine in chrome but in safari it's not working, what is the best solution ?
推荐答案
这在 Safari 中不受支持.具体来说,不支持 scrollIntoViewOptions
,因此您需要为此找到一个 polyfill 或完全采用另一种方法.
This is not supported in Safari. Specifically, scrollIntoViewOptions
is not supported, so you'll need to find a polyfill for this or employ another method entirely.
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
这篇关于scrollIntoView 在 safari 浏览器中没有按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!