More actions
No edit summary |
No edit summary Tag: Reverted |
||
| Line 15: | Line 15: | ||
}); | }); | ||
/ | /* Crear y agregar el botón flotante al cargar la página /* | ||
document.addEventListener("DOMContentLoaded", function () { | document.addEventListener("DOMContentLoaded", function () { | ||
const backToTopButton = document.createElement("div"); | const backToTopButton = document.createElement("div"); | ||
| Line 24: | Line 24: | ||
}); | }); | ||
/ | /* Función para volver al inicio /* | ||
function scrollToTop() { | function scrollToTop() { | ||
window.scrollTo({ | window.scrollTo({ | ||
| Line 32: | Line 32: | ||
} | } | ||
/ | /* Mostrar el botón al hacer scroll hacia abajo /* | ||
window.addEventListener("scroll", function () { | window.addEventListener("scroll", function () { | ||
const backToTopButton = document.getElementById("backToTop"); | const backToTopButton = document.getElementById("backToTop"); | ||
Revision as of 19:52, 16 November 2024
/* Any JavaScript here will be loaded for all users on every page load. */
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 50) {
document.getElementById("navbar").className = "scrolled";
} else {
document.getElementById("navbar").className = "";
}
}
document.getElementById('scrollTop').addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
/* Crear y agregar el botón flotante al cargar la página /*
document.addEventListener("DOMContentLoaded", function () {
const backToTopButton = document.createElement("div");
backToTopButton.id = "backToTop";
backToTopButton.textContent = "↑"; // Flecha hacia arriba
backToTopButton.onclick = scrollToTop;
document.body.appendChild(backToTopButton);
});
/* Función para volver al inicio /*
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: "smooth" // Desplazamiento suave
});
}
/* Mostrar el botón al hacer scroll hacia abajo /*
window.addEventListener("scroll", function () {
const backToTopButton = document.getElementById("backToTop");
if (window.scrollY > 200) {
backToTopButton.classList.add("show");
} else {
backToTopButton.classList.remove("show");
}
});