mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-05 22:38:11 +00:00
Scroll lock przy otwartym modalu
This commit is contained in:
+26
-1
@@ -82,7 +82,7 @@
|
||||
</template>
|
||||
|
||||
<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';
|
||||
|
||||
@@ -163,6 +163,31 @@ export default defineComponent({
|
||||
async mounted() {
|
||||
this.updateStorage();
|
||||
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: {
|
||||
|
||||
@@ -202,7 +202,7 @@ export default defineComponent({
|
||||
this.search();
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', this.handleScroll);
|
||||
window.addEventListener('wheel', this.handleScroll);
|
||||
},
|
||||
|
||||
mounted() {
|
||||
@@ -212,7 +212,7 @@ export default defineComponent({
|
||||
},
|
||||
|
||||
deactivated() {
|
||||
window.removeEventListener('scroll', this.handleScroll);
|
||||
window.removeEventListener('wheel', this.handleScroll);
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
@@ -236,7 +236,7 @@ export default defineComponent({
|
||||
},
|
||||
|
||||
activated() {
|
||||
window.addEventListener('scroll', this.handleScroll);
|
||||
window.addEventListener('wheel', this.handleScroll);
|
||||
|
||||
if (this.timetableId) {
|
||||
this.searchersValues['search-train'] = `#${this.timetableId}`;
|
||||
@@ -249,7 +249,7 @@ export default defineComponent({
|
||||
},
|
||||
|
||||
deactivated() {
|
||||
window.removeEventListener('scroll', this.handleScroll);
|
||||
window.removeEventListener('wheel', this.handleScroll);
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
@@ -17,10 +17,15 @@ export default defineComponent({
|
||||
methods: {
|
||||
selectModalTrain(trainId: string) {
|
||||
this.store.chosenModalTrainId = trainId;
|
||||
document.body.classList.add('no-scroll');
|
||||
},
|
||||
|
||||
closeModal() {
|
||||
this.store.chosenModalTrainId = undefined;
|
||||
|
||||
setTimeout(() => {
|
||||
document.body.classList.remove('no-scroll');
|
||||
}, 150);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -25,10 +25,10 @@ export default defineComponent({
|
||||
},
|
||||
|
||||
activated() {
|
||||
window.addEventListener('scroll', this.handleScroll);
|
||||
window.addEventListener('wheel', this.handleScroll);
|
||||
},
|
||||
|
||||
deactivated() {
|
||||
window.removeEventListener('scroll', this.handleScroll);
|
||||
window.removeEventListener('wheel', this.handleScroll);
|
||||
},
|
||||
});
|
||||
|
||||
+1
-1
@@ -51,6 +51,7 @@ export const useStore = defineStore('store', {
|
||||
trains: DataStatus.Loading,
|
||||
},
|
||||
|
||||
blockScroll: false,
|
||||
listenerLaunched: false,
|
||||
} as StoreState),
|
||||
|
||||
@@ -395,4 +396,3 @@ export const useStore = defineStore('store', {
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ export interface StoreState {
|
||||
};
|
||||
|
||||
listenerLaunched: boolean;
|
||||
blockScroll: boolean;
|
||||
}
|
||||
|
||||
export interface APIData {
|
||||
|
||||
+13
-5
@@ -25,6 +25,15 @@ body {
|
||||
padding: 0;
|
||||
font-family: 'Quicksand', sans-serif;
|
||||
overflow-y: scroll;
|
||||
|
||||
&.no-scroll {
|
||||
overflow-y: hidden;
|
||||
padding-right: 17px;
|
||||
|
||||
@include smallScreen() {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*:focus-visible {
|
||||
@@ -37,16 +46,15 @@ body {
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
width: 0.5rem;
|
||||
height: 0.5rem;
|
||||
width: 17px;
|
||||
height: 17px;
|
||||
|
||||
&-track {
|
||||
background: #222;
|
||||
background-color: #222;
|
||||
}
|
||||
|
||||
&-thumb {
|
||||
border-radius: 1rem;
|
||||
background: #777;
|
||||
background-color: #777;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user