[英]I need to horizontally scroll to a div id using React.JS ?
scrollFunc()
{
document.getElementById("myID").scrollIntoView({"block":"center"})
}
I tried scrollIntoView({"block":"center"}) works perfect in chrome but has issues on Internet Explorer ! 我尝试了scrollIntoView({“ block”:“ center”})在chrome中可以正常使用,但是Internet Explorer上有问题!
scrollIntoView has partial support in IE/Edge. scrollIntoView在IE / Edge中具有部分支持。
scrollIntoView({"block":"center"})
is not supported by IE/Edge IE / Edge不支持
scrollIntoView({"block":"center"})
scrollIntoView(true)
which corresponds to scrollIntoView(true)
对应于 scrollIntoView({block: "start", inline: "nearest"})
scrollIntoView(false)
which corresponds to scrollIntoView(false)
对应于 scrollIntoView({block: "end", inline: "nearest"})
I would recommend using other API or approach if you need {"block":"center"}
. 如果需要
{"block":"center"}
我建议使用其他API或方法。
Read more about it here. 在此处了解更多信息。
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView https://caniuse.com/#search=scroll https://developer.mozilla.org/zh-CN/docs/Web/API/Element/scrollIntoView https://caniuse.com/#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. 要获取页面中任何元素的位置,您可以像这样使用'getBoundingClientRect'方法,并使用window.scrollTo()滚动到该特定位置。
var htmlElement = document.getElementById('container'); var elementPosition = element.getBoundingClientRect() window.scrollTo(elementPosition.left, 0)
Also refer this link for more learning: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect 另请参阅此链接以获取更多信息: https : //developer.mozilla.org/zh-CN/docs/Web/API/Element/getBoundingClientRect
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.