Przejdź do zawartości

MediaWiki:Common.js: Różnice pomiędzy wersjami

Z Horyzont Zdarzeń
Nie podano opisu zmian
Nie podano opisu zmian
Znacznik: Wycofane
Linia 1: Linia 1:
// === Nowy przycisk "Wróć na górę" z SVG ===
// === Przycisk "Wróć na górę" z SVG ===
const scrollButton = document.createElement("button");
const scrollButton = document.createElement("button");
scrollButton.id = "scrollTopBtn";
scrollButton.id = "scrollTopBtn";
Linia 11: Linia 11:
document.body.appendChild(scrollButton);
document.body.appendChild(scrollButton);


// Pokaż/ukryj w zależności od scrolla
// Akcja kliknięcia – scroll do góry
window.onscroll = function() {
scrollButton.onclick = () => {
    const btn = document.getElementById("scrollTopBtn");
    if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) {
        btn.style.display = "flex";
        btn.style.alignItems = "center";
        btn.style.justifyContent = "center";
    } else {
        btn.style.display = "none";
    }
};
 
// Akcja kliknięcia
scrollButton.onclick = function() {
     window.scrollTo({ top: 0, behavior: 'smooth' });
     window.scrollTo({ top: 0, behavior: 'smooth' });
};
};


$(document).ready(function() {
$(document).ready(function () {
     var scrollBtn = document.getElementById("scrollTopBtn");
     const scrollBtn = document.getElementById("scrollTopBtn");


     window.addEventListener("scroll", function() {
     window.addEventListener("scroll", () => {
         var footerHeight = document.querySelector(".mw-footer") ? document.querySelector(".mw-footer").offsetHeight : 0;
         const footer = document.querySelector(".mw-footer");
         var windowHeight = window.innerHeight;
        const footerHeight = footer ? footer.offsetHeight : 0;
         var bodyHeight = document.body.scrollHeight;
         const scrollY = window.scrollY;
        var scrollY = window.scrollY;
        const windowHeight = window.innerHeight;
         const bodyHeight = document.body.scrollHeight;


         // Czy jesteśmy blisko stopki?
         // Widoczność przycisku
         if (scrollY + windowHeight > bodyHeight - footerHeight) {
         if (scrollY > 300) {
             scrollBtn.style.bottom = (footerHeight + 20) + "px"; // przesuń w górę
             scrollBtn.style.display = "flex";
            scrollBtn.style.alignItems = "center";
            scrollBtn.style.justifyContent = "center";
         } else {
         } else {
             scrollBtn.style.bottom = "100px"; // normalnie
             scrollBtn.style.display = "none";
         }
         }
    });


    // Pokaż przycisk po scrollu
        // Unikaj nakładania na stopkę
    window.addEventListener("scroll", function() {
         if (scrollY + windowHeight > bodyHeight - footerHeight) {
         if (document.documentElement.scrollTop > 200) {
             scrollBtn.style.bottom = (footerHeight + 20) + "px";
             scrollBtn.style.display = "block";
         } else {
         } else {
             scrollBtn.style.display = "none";
             scrollBtn.style.bottom = "160px";
         }
         }
     });
     });
});
});

Wersja z 13:42, 1 maj 2025

// === Przycisk "Wróć na górę" z SVG ===
const scrollButton = document.createElement("button");
scrollButton.id = "scrollTopBtn";
scrollButton.title = "Wróć na górę";
scrollButton.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="#1a1a1a" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-up">
    <line x1="12" y1="19" x2="12" y2="5"></line>
    <polyline points="5 12 12 5 19 12"></polyline>
</svg>
`;
document.body.appendChild(scrollButton);

// Akcja kliknięcia – scroll do góry
scrollButton.onclick = () => {
    window.scrollTo({ top: 0, behavior: 'smooth' });
};

$(document).ready(function () {
    const scrollBtn = document.getElementById("scrollTopBtn");

    window.addEventListener("scroll", () => {
        const footer = document.querySelector(".mw-footer");
        const footerHeight = footer ? footer.offsetHeight : 0;
        const scrollY = window.scrollY;
        const windowHeight = window.innerHeight;
        const bodyHeight = document.body.scrollHeight;

        // Widoczność przycisku
        if (scrollY > 300) {
            scrollBtn.style.display = "flex";
            scrollBtn.style.alignItems = "center";
            scrollBtn.style.justifyContent = "center";
        } else {
            scrollBtn.style.display = "none";
        }

        // Unikaj nakładania na stopkę
        if (scrollY + windowHeight > bodyHeight - footerHeight) {
            scrollBtn.style.bottom = (footerHeight + 20) + "px";
        } else {
            scrollBtn.style.bottom = "160px";
        }
    });
});