Search code examples
javascriptscrollsafari

scrollIntoView is not working as expected in safari browser


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' 
 })

this works fine in chrome but in safari it's not working, what is the best solution ?


Solution

  • 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