feat: ajout de la gestion de l'auto-hide du header et amélioration de la réactivité des composants en fonction de la taille de la fenêtre, ainsi que des optimisations CSS pour une meilleure expérience utilisateur sur mobile.
This commit is contained in:
parent
4848a1736f
commit
ebcca466a9
73
assets/vue/app/shared/stores/headerStore.js
Normal file
73
assets/vue/app/shared/stores/headerStore.js
Normal file
@@ -0,0 +1,73 @@
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
export const useHeaderStore = defineStore('header', {
|
||||
state: () => ({
|
||||
isHeaderVisible: true,
|
||||
isAutoHideEnabled: false,
|
||||
lastScrollY: 0,
|
||||
scrollDirection: 'up'
|
||||
}),
|
||||
|
||||
getters: {
|
||||
shouldShowHeader: (state) => {
|
||||
// Si l'auto-hide n'est pas activé, toujours afficher le header
|
||||
if (!state.isAutoHideEnabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Si l'auto-hide est activé, suivre la visibilité
|
||||
return state.isHeaderVisible;
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
enableAutoHide() {
|
||||
this.isAutoHideEnabled = true;
|
||||
},
|
||||
|
||||
disableAutoHide() {
|
||||
this.isAutoHideEnabled = false;
|
||||
this.isHeaderVisible = true; // Toujours visible quand désactivé
|
||||
},
|
||||
|
||||
updateScrollDirection(scrollY) {
|
||||
// Éviter les calculs inutiles si pas d'auto-hide
|
||||
if (!this.isAutoHideEnabled) {
|
||||
this.lastScrollY = scrollY;
|
||||
return;
|
||||
}
|
||||
|
||||
// Détecter la direction du scroll avec un seuil pour éviter les micro-mouvements
|
||||
const scrollDifference = Math.abs(scrollY - this.lastScrollY);
|
||||
|
||||
if (scrollDifference < 5) {
|
||||
// Mouvement trop petit, on ignore
|
||||
return;
|
||||
}
|
||||
|
||||
if (scrollY > this.lastScrollY && scrollY > 100) {
|
||||
// Scroll vers le bas et suffisamment de scroll
|
||||
if (this.scrollDirection !== 'down') {
|
||||
this.scrollDirection = 'down';
|
||||
this.isHeaderVisible = false;
|
||||
}
|
||||
} else if (scrollY < this.lastScrollY) {
|
||||
// Scroll vers le haut
|
||||
if (this.scrollDirection !== 'up') {
|
||||
this.scrollDirection = 'up';
|
||||
this.isHeaderVisible = true;
|
||||
}
|
||||
}
|
||||
|
||||
this.lastScrollY = scrollY;
|
||||
},
|
||||
|
||||
showHeader() {
|
||||
this.isHeaderVisible = true;
|
||||
},
|
||||
|
||||
hideHeader() {
|
||||
this.isHeaderVisible = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user