JSFiddle - React, Tailwind, and code Playground
HTML
<div style="height: 1000px;">
1
</div>
<button onclick="javascript: alo();">Click me!</button>
<div style="height: 500px"></div>
<input type="hidden" id="hfScrollPosition" />
JavaScript
function alo()
{
var x = document.getElementById("hfScrollPosition").value;
document.documentElement.scrollTop = 0;
setTimeout(function() { document.documentElement.scrollTop = x; }, 700);
}
document.onscroll = function () {
document.getElementById("hfScrollPosition").value = document.documentElement.scrollTop;
}