<body>
<button id="btn">滚动</button>
<div id="box" style="height: 300px;overflow: auto;"></div>
<script>
function elFormErrorScrollIntoView(tag) {
const element = document.querySelectorAll(tag)[0];
element.scrollIntoView({
behavior: "smooth",
block: "center"
});
}
for (let i = 0; i < 100; i++) {
const div = document.createElement('div')
div.innerText = i
div.className = 'div'
document.getElementById('box').appendChild(div)
}
document.getElementById('btn').onclick = function () {
elFormErrorScrollIntoView('.div')
}
</script>
</body>
