Please Help regarding auto scroll to hint

Whenever I press the shortcut key for the hint, I have to scroll down manually to see the hint. I want it to auto-scroll to the hint.

element = document.getElementById("Prepladder");
element.scrollIntoView();
element1 = document.getElementById("Marrow");
element1.scrollIntoView();
element2 = document.getElementById("Others");
element2.scrollIntoView();

Try adding these to the respective scripts.

Scripts are the portions of code found between the tags <script></script>.
e.g.

You talked about pressing a shortcut key for the hint and I assumed this was done using JavaScript.

Would you share the remaining part of the Template? You can also copy-paste it here. Just remember to use the ‘Preformatted text’ button on it before sending.
image

Yes, the shortcut key for the hint works but it doesn’t automatically scroll to the hint.
I don’t understand the coding at all. I tried pasting your code to the (script) section but it did not work.
This is the preformatted back template :


image

Where can I download the shared deck with this notetype?

1 Like

I gave a look at the notes and did not find any code that adds a keyboard shortcut for the hints. Am I missing something? Or did you mean something else?

I use the “Keyboard shortcuts” add-on for the hints.
In other decks that I use (like AnKing), it works well, it auto-scrolls down on itself. In fact, if I do not use the shortcut key and just left-click the hint, it still auto-scrolls but not in this(ENT-Panacea) deck.

I see, I do not know about the add-on so I am afraid I can’t help you in that regard.

If you just want to scroll to the hint after clicking on the respective link, the following code, while probably not the cleanest, should do the job.
It is designed for a maximum of 10 hint fields and you have to add it to the Back Template.

<script>
var hint0 = document.getElementsByClassName('hints')[0];
hint0.addEventListener("click", scrollTo0);

function scrollTo0() {
document.getElementsByClassName("hints")[0].scrollIntoView();
}
</script>

<script>
var hint1 = document.getElementsByClassName('hints')[1];
hint1.addEventListener("click", scrollTo1);

function scrollTo1() {
document.getElementsByClassName("hints")[1].scrollIntoView();
}
</script>

<script>
var hint2 = document.getElementsByClassName('hints')[2];
hint2.addEventListener("click", scrollTo2);

function scrollTo2() {
document.getElementsByClassName("hints")[2].scrollIntoView();
}
</script>

<script>
var hint3 = document.getElementsByClassName('hints')[3];
hint3.addEventListener("click", scrollTo3);

function scrollTo3() {
document.getElementsByClassName("hints")[3].scrollIntoView();
}
</script>

<script>
var hint4 = document.getElementsByClassName('hints')[4];
hint4.addEventListener("click", scrollTo4);

function scrollTo4() {
document.getElementsByClassName("hints")[4].scrollIntoView();
}
</script>

<script>
var hint5 = document.getElementsByClassName('hints')[5];
hint5.addEventListener("click", scrollTo5);

function scrollTo5() {
document.getElementsByClassName("hints")[5].scrollIntoView();
}
</script>

<script>
var hint6 = document.getElementsByClassName('hints')[6];
hint6.addEventListener("click", scrollTo6);

function scrollTo6() {
document.getElementsByClassName("hints")[6].scrollIntoView();
}
</script>

<script>
var hint7 = document.getElementsByClassName('hints')[7];
hint7.addEventListener("click", scrollTo7);

function scrollTo7() {
document.getElementsByClassName("hints")[7].scrollIntoView();
}
</script>

<script>
var hint8 = document.getElementsByClassName('hints')[8];
hint8.addEventListener("click", scrollTo8);

function scrollTo8() {
document.getElementsByClassName("hints")[8].scrollIntoView();
}
</script>

<script>
var hint9 = document.getElementsByClassName('hints')[9];
hint9.addEventListener("click", scrollTo9);

function scrollTo9() {
document.getElementsByClassName("hints")[9].scrollIntoView();
}
</script>
2 Likes

Here’s the add-on:
https://ankiweb.net/shared/info/24411424
Your code works perfectly with the click but not the shortcut key. If you could look into it, please let me know.
Many thanks for your assistance and time.

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