Moved scroll to top javascript code into the vue mounted method

This commit is contained in:
Chris Kankiewicz
2020-02-17 11:31:15 -07:00
parent 0ae07f6beb
commit dfb13e2955
2 changed files with 12 additions and 12 deletions

View File

@@ -3,7 +3,7 @@ window.Vue = require('vue');
Vue.component('file-info-modal', require('./components/file-info-modal.vue').default);
const app = new Vue({
el: "#app",
el: '#app',
data: function() {
return {
search: ''
@@ -19,17 +19,17 @@ const app = new Vue({
},
mounted: function() {
window.addEventListener('keyup', e => e.keyCode == 191 && this.$refs.searchInput.focus());
let scrollToTop = this.$refs.scrollToTop;
window.addEventListener('scroll', function() {
if (window.scrollY > 10) {
scrollToTop.classList.remove('hidden');
} else {
scrollToTop.classList.add('hidden');
}
});
}
});
let hljs = require('highlight.js');
hljs.initHighlightingOnLoad();
let link = document.getElementById('scroll-to-top');
window.addEventListener('scroll', function() {
if (window.scrollY > 10) {
link.classList.remove('hidden');
} else {
link.classList.add('hidden');
}
});

View File

@@ -1,10 +1,10 @@
<div class="fixed bottom-0 left-0 right-0 pointer-events-none">
<div class="container flex justify-end mx-auto px-4 py-10">
<a id="scroll-to-top"
<button id="scroll-to-top" ref="scrollToTop"
class="flex justify-center items-center w-12 h-12 right-0 rounded-full shadow-lg bg-blue-600 text-white cursor-pointer pointer-events-auto hover:bg-blue-700 hidden"
onclick="window.scrollTo({ top: 0, left: 0, behavior: 'smooth' });" title="Scroll to Top"
>
<i class="fas fa-arrow-up fa-lg"></i>
</a>
</button>
</div>
</div>