I'm currently developing a Vue.js project and I want to implement a feature where a "back to top" button appears when the user scrolls beyond a certain point. However, I'm encountering an issue without using JQuery. Can you help me troubleshoot this problem?
Here is part of my template code:
<div class="scroll">
<span class="scroll_button">Top</span>
</div>
And in the mounted() function:
const toTop = document.getElementsByClassName('scroll').addEventListener('scroll', function() {
if (window.scrollY > 0) {
this.classList.add('shown')
}
});
toTop();