Przejdź do zawartości

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

Z Horyzont Zdarzeń
Utworzono nową stronę "Umieszczony tutaj kod JavaScript zostanie załadowany przez każdego użytkownika, podczas każdego ładowania strony.: // === Dodany przycisk "Wróć na górę" === // Tworzymy przycisk const scrollButton = document.createElement("button"); scrollButton.innerHTML = "↑"; scrollButton.id = "scrollTopBtn"; scrollButton.title = "Wróć na górę"; document.body.appendChild(scrollButton); // Pokazywanie przycisku po scrollowaniu window.onscroll = function() {s…"
 
Nie podano opisu zmian
Linia 1: Linia 1:
/* Umieszczony tutaj kod JavaScript zostanie załadowany przez każdego użytkownika, podczas każdego ładowania strony. */
// === Nowy przycisk "Wróć na górę" z SVG ===
// === Dodany przycisk "Wróć na górę" ===
 
// Tworzymy przycisk
const scrollButton = document.createElement("button");
const scrollButton = document.createElement("button");
scrollButton.innerHTML = "↑";
scrollButton.id = "scrollTopBtn";
scrollButton.id = "scrollTopBtn";
scrollButton.title = "Wróć na górę";
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);
document.body.appendChild(scrollButton);


// Pokazywanie przycisku po scrollowaniu
// Pokaż/ukryj w zależności od scrolla
window.onscroll = function() {scrollFunction()};
window.onscroll = function() {
 
function scrollFunction() {
     const btn = document.getElementById("scrollTopBtn");
     const btn = document.getElementById("scrollTopBtn");
     if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) {
     if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) {
         btn.style.display = "block";
         btn.style.display = "flex";
        btn.style.alignItems = "center";
        btn.style.justifyContent = "center";
     } else {
     } else {
         btn.style.display = "none";
         btn.style.display = "none";
     }
     }
}
};
 
// Scrollowanie na górę po kliknięciu
function topFunction() {
    document.body.scrollTop = 0;
    document.documentElement.scrollTop = 0;
}


scrollButton.onclick = topFunction;
// Akcja kliknięcia
scrollButton.onclick = function() {
    window.scrollTo({ top: 0, behavior: 'smooth' });
};

Wersja z 15:14, 27 kwi 2025

// === Nowy 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);

// Pokaż/ukryj w zależności od scrolla
window.onscroll = function() {
    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' });
};