Recently I noticed that while performing ajax page updates (appends to a block, to be specific, like in "Show more comments" scenarios) Chrome started performing some kind of automatic scroll in order to keep the clicked element in view, it seems.
What is this? Why has it been introduced and how to get rid of this behaviour?
Minimum(ish) reproducible code here:
$(document).ready(function() {
var html = $(".container").html();
$("#load-more").click(function(){
$(".container").append(html);
})
})
.container {
width: 400px;
margin: 0 auto;
background-color: aqua;
padding: 1em;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="container">
<article>
<h3>Foo Bar 1</h3>
<p>hello world</p>
</article>
<article>
<h3>Foo Bar 2</h3>
<p>hello world</p>
</article>
<article>
<h3>Foo Bar 3</h3>
<p>hello world</p>
</article>
</div>
<button id="load-more">load more</button>
</body>
</html>
Note how in Chrome(ium) the clicked button stays in view, contrary to what one would expect.