I have two overflowing elements on the page, I would like to call ScrollIntoView at the same time for child elements within both of them.
The following works in Firefox, but not Chrome. Is this a bug?
const button = document.querySelector('button');
const one = document.querySelector('.one');
const two = document.querySelector('.two');
button.addEventListener('click', () => {
one.scrollIntoView({ block: 'center', behavior: 'smooth' });
two.scrollIntoView({ block: 'center', behavior: 'smooth' });
});
body {
text-align: center;
}
#container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
width: 100%;
height: 130px;
}
#container > div {
max-height: 200px;
overflow-y: auto;
border: 1px solid black;
}
button {
font-size: 1.5rem;
margin: 0.5rem auto;
}
<div id="container">
<div>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
<h1 class="one">Boo!</h1>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
</div>
<div>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
<h1 class="two">Boo!</h1>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
<h1>...</h1>
</div>
</div>
<button>click to scroll</button>