scrollFunc()
{
document.getElementById("myID").scrollIntoView({"block":"center"})
}
I tried scrollIntoView({"block":"center"}) works perfect in chrome but has issues on Internet Explorer !
scrollFunc()
{
document.getElementById("myID").scrollIntoView({"block":"center"})
}
I tried scrollIntoView({"block":"center"}) works perfect in chrome but has issues on Internet Explorer !
Share Improve this question asked Nov 10, 2017 at 7:59 shubham pandeyshubham pandey 772 silver badges6 bronze badges2 Answers
Reset to default 5scrollIntoView has partial support in IE/Edge.
scrollIntoView({"block":"center"})
is not supported by IE/Edge
- You have the option
scrollIntoView(true)
which corresponds to
scrollIntoView({block: "start", inline: "nearest"})
- You have the option
scrollIntoView(false)
which corresponds to
scrollIntoView({block: "end", inline: "nearest"})
I would remend using other API or approach if you need {"block":"center"}
.
Read more about it here.
https://developer.mozilla/en-US/docs/Web/API/Element/scrollIntoView https://caniuse./#search=scroll
Give this a try,
To get the position of any element in page, you can use 'getBoundingClientRect' method like this, and window.scrollTo() to scroll to that particular location.
var htmlElement = document.getElementById('container');
var elementPosition = element.getBoundingClientRect()
window.scrollTo(elementPosition.left, 0)
Also refer this link for more learning: https://developer.mozilla/en-US/docs/Web/API/Element/getBoundingClientRect