replace all w3-include
All checks were successful
Deploy / Deploy to Production (push) Successful in 12s
All checks were successful
Deploy / Deploy to Production (push) Successful in 12s
This commit is contained in:
parent
1570d62287
commit
4642425f43
26 changed files with 283 additions and 80 deletions
50
assets/js/mobile-sticky.js
Normal file
50
assets/js/mobile-sticky.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
let isInitialized = false;
|
||||
|
||||
export function btnSticky(responsiveSmall) {
|
||||
if (isInitialized) return;
|
||||
|
||||
let main = document.querySelector("main");
|
||||
if (!main || !main.classList.contains("page-enquete")) return;
|
||||
|
||||
let bannerPage = main.querySelector("#banner--page");
|
||||
let sectionDl = document.querySelector("#section__dl");
|
||||
let footer = document.querySelector("#site-footer");
|
||||
|
||||
if (!bannerPage || !sectionDl || !footer) return;
|
||||
|
||||
function checkScroll() {
|
||||
const screenWidth = window.innerWidth;
|
||||
|
||||
// Vérifier que l'écran est plus petit que responsiveSmall
|
||||
if (screenWidth >= responsiveSmall) {
|
||||
bannerPage.classList.remove('is-visible');
|
||||
bannerPage.style.transform = 'translateY(0)';
|
||||
return;
|
||||
}
|
||||
|
||||
const sectionTop = sectionDl.getBoundingClientRect().top;
|
||||
const footerTop = footer.getBoundingClientRect().top;
|
||||
const windowHeight = window.innerHeight;
|
||||
|
||||
// Activer le banner quand #section__dl arrive en bas de l'écran
|
||||
if (sectionTop <= windowHeight) {
|
||||
bannerPage.classList.add('is-visible');
|
||||
|
||||
// Pousser le banner vers le haut si le footer arrive en bas de l'écran
|
||||
if (footerTop < windowHeight) {
|
||||
const pushUp = windowHeight - footerTop;
|
||||
bannerPage.style.transform = `translateY(-${pushUp}px)`;
|
||||
} else {
|
||||
bannerPage.style.transform = 'translateY(0)';
|
||||
}
|
||||
} else {
|
||||
bannerPage.classList.remove('is-visible');
|
||||
bannerPage.style.transform = 'translateY(0)';
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', checkScroll);
|
||||
checkScroll();
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue