Scroll lock przy otwartym modalu

This commit is contained in:
2022-08-29 19:12:19 +02:00
parent 03950eef66
commit 96de3f0dcc
8 changed files with 1015 additions and 976 deletions
+26 -1
View File
@@ -82,7 +82,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, defineComponent, provide, ref } from 'vue'; import { computed, defineComponent, provide, ref, watch } from 'vue';
import Clock from './components/App/Clock.vue'; import Clock from './components/App/Clock.vue';
@@ -163,6 +163,31 @@ export default defineComponent({
async mounted() { async mounted() {
this.updateStorage(); this.updateStorage();
this.setReleaseURL(); this.setReleaseURL();
function preventScroll(e: Event) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return false;
}
watch(
() => this.store.blockScroll,
(value) => {
if (value) {
document.body.classList.add('no-scroll');
// document.querySelector('#app')!.addEventListener('wheel', preventScroll, { passive: false, });
// document.querySelector('#app')!.addEventListener('touchmove', preventScroll, { passive: false });
return;
}
document.body.classList.remove('no-scroll');
// document.querySelector('#app')!.removeEventListener('wheel', preventScroll);
// document.querySelector('#app')!.removeEventListener('touchmove', preventScroll);
}
);
}, },
methods: { methods: {
@@ -202,7 +202,7 @@ export default defineComponent({
this.search(); this.search();
} }
window.addEventListener('scroll', this.handleScroll); window.addEventListener('wheel', this.handleScroll);
}, },
mounted() { mounted() {
@@ -212,7 +212,7 @@ export default defineComponent({
}, },
deactivated() { deactivated() {
window.removeEventListener('scroll', this.handleScroll); window.removeEventListener('wheel', this.handleScroll);
}, },
methods: { methods: {
@@ -236,7 +236,7 @@ export default defineComponent({
}, },
activated() { activated() {
window.addEventListener('scroll', this.handleScroll); window.addEventListener('wheel', this.handleScroll);
if (this.timetableId) { if (this.timetableId) {
this.searchersValues['search-train'] = `#${this.timetableId}`; this.searchersValues['search-train'] = `#${this.timetableId}`;
@@ -249,7 +249,7 @@ export default defineComponent({
}, },
deactivated() { deactivated() {
window.removeEventListener('scroll', this.handleScroll); window.removeEventListener('wheel', this.handleScroll);
}, },
methods: { methods: {
+5
View File
@@ -17,10 +17,15 @@ export default defineComponent({
methods: { methods: {
selectModalTrain(trainId: string) { selectModalTrain(trainId: string) {
this.store.chosenModalTrainId = trainId; this.store.chosenModalTrainId = trainId;
document.body.classList.add('no-scroll');
}, },
closeModal() { closeModal() {
this.store.chosenModalTrainId = undefined; this.store.chosenModalTrainId = undefined;
setTimeout(() => {
document.body.classList.remove('no-scroll');
}, 150);
}, },
}, },
}); });
+2 -2
View File
@@ -25,10 +25,10 @@ export default defineComponent({
}, },
activated() { activated() {
window.addEventListener('scroll', this.handleScroll); window.addEventListener('wheel', this.handleScroll);
}, },
deactivated() { deactivated() {
window.removeEventListener('scroll', this.handleScroll); window.removeEventListener('wheel', this.handleScroll);
}, },
}); });
+1 -1
View File
@@ -51,6 +51,7 @@ export const useStore = defineStore('store', {
trains: DataStatus.Loading, trains: DataStatus.Loading,
}, },
blockScroll: false,
listenerLaunched: false, listenerLaunched: false,
} as StoreState), } as StoreState),
@@ -395,4 +396,3 @@ export const useStore = defineStore('store', {
}, },
}, },
}); });
+1
View File
@@ -42,6 +42,7 @@ export interface StoreState {
}; };
listenerLaunched: boolean; listenerLaunched: boolean;
blockScroll: boolean;
} }
export interface APIData { export interface APIData {
+13 -5
View File
@@ -25,6 +25,15 @@ body {
padding: 0; padding: 0;
font-family: 'Quicksand', sans-serif; font-family: 'Quicksand', sans-serif;
overflow-y: scroll; overflow-y: scroll;
&.no-scroll {
overflow-y: hidden;
padding-right: 17px;
@include smallScreen() {
padding: 0;
}
}
} }
*:focus-visible { *:focus-visible {
@@ -37,16 +46,15 @@ body {
} }
::-webkit-scrollbar { ::-webkit-scrollbar {
width: 0.5rem; width: 17px;
height: 0.5rem; height: 17px;
&-track { &-track {
background: #222; background-color: #222;
} }
&-thumb { &-thumb {
border-radius: 1rem; background-color: #777;
background: #777;
} }
} }