You need to scroll down to see the buttons in action. I recommend you to put this in the Footer.
On your live page you will only see the buttons appear when you scroll down.
Use only one button, normal or left
On your live page you will only see the buttons appear when you scroll down.
Use only one button, normal or left
Back to top
Back to top
<script>
// Esperar a que el DOM esté completamente cargado
document.addEventListener('DOMContentLoaded', function() {
// Obtener todas las referencias a los botones
var scrollToTopButtons = document.querySelectorAll('.fb-top-btn');
// Ocultar los botones por defecto
scrollToTopButtons.forEach(function(button) {
button.style.opacity = '0';
button.style.visibility = 'hidden';
});
// Agregar un evento de scroll a la ventana
window.addEventListener('scroll', function() {
if (window.scrollY > 500) {
// Mostrar los botones con clase fb-top-btn
scrollToTopButtons.forEach(function(button) {
button.style.opacity = '1';
button.style.visibility = 'visible';
});
} else {
// Ocultar los botones con clase fb-top-btn
scrollToTopButtons.forEach(function(button) {
button.style.opacity = '0';
button.style.visibility = 'hidden';
});
}
});
// Agregar un evento de clic a cada botón
scrollToTopButtons.forEach(function(button) {
button.addEventListener('click', function(event) {
event.preventDefault(); // Prevenir el comportamiento predeterminado del enlace
// Desplazarse al principio de la página de manera suave
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
});
});
</script>