Skip to content

Commit 4f9e2ae

Browse files
committed
auto scroll
1 parent 03cadc1 commit 4f9e2ae

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

web/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"vue": "^2.5.2",
2020
"vue-lazyload": "^1.1.4",
2121
"vue-router": "^3.0.1",
22+
"vue-scrollto": "^2.8.0",
2223
"vuex": "^3.0.1"
2324
},
2425
"devDependencies": {

web/src/components/PlayerBlock.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<router-link :to="`player/${uuid}`">
3-
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 searchbox">
3+
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 searchbox" :data-uuid="uuid">
44
<div class="panel panel-default">
55
<div class="panel-body">
66
<div class="media">

web/src/components/PlayerList.vue

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<script>
2222
import axios from 'axios';
2323
import { mapState, mapMutations } from 'vuex';
24+
import VueScrollTo from 'vue-scrollto';
2425
2526
import PlayerBlock from './PlayerBlock';
2627
import Footer from './Footer';
@@ -56,10 +57,12 @@ export default {
5657
},
5758
computed: mapState([
5859
'playerList',
60+
'scrollOffset',
5961
]),
6062
methods: {
6163
...mapMutations([
6264
'setPlayerList',
65+
'setScrollOffset',
6366
]),
6467
lazyload() {
6568
clearTimeout(this.timer);
@@ -86,6 +89,27 @@ export default {
8689
});
8790
},
8891
},
92+
beforeRouteLeave(to, from, next) {
93+
const uuid = to.params.uuid;
94+
this.setScrollOffset({
95+
uuid,
96+
});
97+
next();
98+
},
99+
updated() {
100+
this.$nextTick(function () {
101+
if (this.scrollOffset.length === 32) {
102+
setTimeout(() => {
103+
VueScrollTo.scrollTo(`[data-uuid="${this.scrollOffset}"]`, 500, {
104+
duration: 500,
105+
easing: 'ease-in',
106+
offset: -65,
107+
cancelable: false,
108+
});
109+
}, 100);
110+
}
111+
});
112+
},
89113
components: {
90114
playerblock: PlayerBlock,
91115
nyaaFooter: Footer,

web/src/components/PlayerPage.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ export default {
116116
clearInterval(timer);
117117
}
118118
}, 100);
119+
this.$el.scrollTop = 0;
120+
},
121+
updated() {
119122
},
120123
components: {
121124
NameHistory,

web/src/main.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Vue from 'vue';
55
import Vuex from 'vuex';
66
import BootstrapVue from 'bootstrap-vue';
77
import VueLazyload from 'vue-lazyload';
8+
import VueScrollTo from 'vue-scrollto';
89
import 'bootstrap/dist/css/bootstrap.css';
910
import 'bootstrap-vue/dist/bootstrap-vue.css';
1011

@@ -17,6 +18,7 @@ Vue.use(BootstrapVue);
1718
Vue.use(VueLazyload, {
1819
lazyComponent: true,
1920
});
21+
Vue.use(VueScrollTo);
2022
Vue.use(Vuex);
2123

2224
export const store = new Vuex.Store({
@@ -29,6 +31,7 @@ export const store = new Vuex.Store({
2931
},
3032
players: {},
3133
playerList: [],
34+
scrollOffset: '',
3235
},
3336
mutations: {
3437
setInfo(state, payload) {
@@ -46,6 +49,9 @@ export const store = new Vuex.Store({
4649
...payload.playerList,
4750
];
4851
},
52+
setScrollOffset(state, payload) {
53+
state.scrollOffset = payload.uuid;
54+
},
4955
},
5056
});
5157

0 commit comments

Comments
 (0)