index-shop/assets/js/onload.js
isUnknown a3620a1f5f
Some checks are pending
Deploy / Deploy to Production (push) Waiting to run
first commit
2025-12-10 15:12:06 +01:00

90 lines
No EOL
2.5 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

window.onload = function () {
headerShrink();
initCart();
toggleDonationButton();
videos();
};
window.onscroll = function () {
headerShrink();
toggleDonationButton();
};
function initCart() {
const items = document.querySelectorAll('.store__product .link-block');
const header = document.querySelector('#site-header');
}
function headerShrink() {
const header = document.getElementById('site-header');
const scrollPosition = window.scrollY || document.documentElement.scrollTop;
if (scrollPosition > 100) {
header.classList.add('is-shrinked');
} else {
header.classList.remove('is-shrinked');
}
}
function toggleDonationButton() {
const btn = document.getElementById('btn--don__mobile');
const section = document.getElementById('section__donation');
const footer = document.getElementById('site-footer');
if (!btn || !section || !footer) return; // sécurité
const scrollTop = window.scrollY || window.pageYOffset;
const triggerPoint = section.offsetTop + section.offsetHeight / 2;
// 1⃣ Gestion de la visibilité du bouton
if (scrollTop >= triggerPoint) {
btn.classList.add('is-visible');
} else {
btn.classList.remove('is-visible');
}
// 2⃣ Gestion du stickiness quand le footer apparaît
const footerRect = footer.getBoundingClientRect();
const windowHeight = window.innerHeight;
if (footerRect.top < windowHeight) {
// Le footer est visible dans la fenêtre
btn.classList.add('is-sticky');
} else {
btn.classList.remove('is-sticky');
}
}
function videos(){
console.log("video");
let section = document.getElementById("section__video");
console.log(section);
let videoslinks = document.querySelectorAll(".videos__li");
videoslinks.forEach(function (video, index) {
video.addEventListener("click", (event) => {
let data = video.getAttribute('data-video');
var div = document.createElement('section');
div.id = "video__fullscreen";
div.innerHTML = '<button id="video__close">✕</button>\
<iframe\
src="' + data + '"\
style="aspect-ratio: 9/16; width: 100%; border: 0"\
allow="autoplay; fullscreen; picture-in-picture"\
allowfullscreen ></iframe>';
document.body.appendChild(div);
document.body.classList.add("is-fullscreen");
let close = document.querySelector("#video__close");
close.addEventListener("click", (event) => {
div.remove();
document.body.classList.remove("is-fullscreen");
});
});
});
}