MediaWiki:Common.js: Różnice pomiędzy wersjami
Wygląd
Nie podano opisu zmian Znacznik: Wycofane |
Nie podano opisu zmian Znacznik: Wycofane |
||
| Linia 1: | Linia 1: | ||
// === Przycisk "Wróć na górę" z SVG === | // === Przycisk "Wróć na górę" z SVG === | ||
$(document).ready(function () { | $(document).ready(function () { | ||
if (document.getElementById("scrollTopBtn")) return; | |||
const scrollButton = document.createElement("button"); | const scrollButton = document.createElement("button"); | ||
scrollButton.id = "scrollTopBtn"; | scrollButton.id = "scrollTopBtn"; | ||
scrollButton.title = "Wróć na górę"; | scrollButton.title = "Wróć na górę"; | ||
scrollButton.innerHTML = ` | 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"> | |||
<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); | ||
| Linia 26: | Linia 28: | ||
const scrollY = window.pageYOffset || document.documentElement.scrollTop; | const scrollY = window.pageYOffset || document.documentElement.scrollTop; | ||
// | // Widoczność | ||
btn.style.display = scrollY > 300 ? "flex" : "none"; | btn.style.display = scrollY > 300 ? "flex" : "none"; | ||
// | // Oblicz dolne przesunięcie (nie bliżej niż 40px od dołu) | ||
const overlap = scrollY + windowHeight - (bodyHeight - footerHeight); | const overlap = scrollY + windowHeight - (bodyHeight - footerHeight); | ||
const calculatedBottom = overlap > 0 ? Math.max(40, overlap + 20) : 40; | |||
btn.style.bottom = `${calculatedBottom}px`; | |||
}, { passive: true }); | }, { passive: true }); | ||
}); | }); | ||
Wersja z 13:58, 1 maj 2025
// === Przycisk "Wróć na górę" z SVG ===
$(document).ready(function () {
if (document.getElementById("scrollTopBtn")) return;
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">
<line x1="12" y1="19" x2="12" y2="5"></line>
<polyline points="5 12 12 5 19 12"></polyline>
</svg>
`;
document.body.appendChild(scrollButton);
// Scroll to top
scrollButton.addEventListener("click", () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
// Scroll behavior
window.addEventListener("scroll", () => {
const btn = document.getElementById("scrollTopBtn");
const footer = document.querySelector(".mw-footer");
const footerHeight = footer ? footer.offsetHeight : 0;
const windowHeight = window.innerHeight;
const bodyHeight = document.body.scrollHeight;
const scrollY = window.pageYOffset || document.documentElement.scrollTop;
// Widoczność
btn.style.display = scrollY > 300 ? "flex" : "none";
// Oblicz dolne przesunięcie (nie bliżej niż 40px od dołu)
const overlap = scrollY + windowHeight - (bodyHeight - footerHeight);
const calculatedBottom = overlap > 0 ? Math.max(40, overlap + 20) : 40;
btn.style.bottom = `${calculatedBottom}px`;
}, { passive: true });
});