当用户单击 div 时,我使用以下 JavaScript 代码将 div 滚动到 View 中。
<script>
function showDiv2() {
document.getElementById('about').style.display = "none";
document.getElementById('terms').style.display = "none";
document.getElementById('breaker').style.display = "block";
document.getElementById('contact_us').style.display = "block";
document.getElementById( 'contact_us' ).scrollIntoView('slow');
}
</script>
这段代码可以工作并将div滚动到 View 中,但没有任何效果,页面不是平滑地向下滚动到我的div,而是跳转到div。有没有办法让我顺利并缓慢地向下滚动到我的 div ?谢谢
最佳答案
根据Element.scrollIntoView()
documentation试试这个:
element.scrollIntoView({block: "end", behavior: "smooth"});
但您必须记住,这是一项实验性功能,仅在 Firefox 中有效
关于javascript将div滚动到 View 中并具有平滑的滚动效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30895313/