Scroll to a designated position automatically

At the click of a button, I could scroll to a given location using

<button onclick="document.documentElement.scrollTop = fieldContent;" id="myBtn">Button</button>

where fieldContent is the variable containing a number for the scroll position.

However, I want to do this automatically by adding the javascript below to my back template but it not working out. I know about using the answer id but it doesn’t allow the flexibility I seek. The script below however works fine on anki (desktop). Is there a way I could work around this?

<script>
document.documentElement.scrollTop =fieldContent;
</script>

So after a long search, this little trick seemed to be the solution:

setTimeout(function() {
    document.documentElement.scrollTop = fieldContent;
}, 200);

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.