Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
Make button disapper if hash changing during scroll

So, I'm using fullpage.js jquery for scrolling on my website.
Each scroll section is divided in hashes, like index.html/#firstPage etc.
I've made a fixed scroll to top button, but I wanna make him disappear if hash equals #firstPage.
I've made a Js script too, but it doesn't work. Any ideas?

mybutton = document.getElementById("scroll_top_button");

var stringHash = window.location.hash;
console.log(stringHash); // Returns hash and it works
function hashDisappear() {
  if (stringHash == "#firstPage") {// this thing doesn't work at all.
    mybutton.style.display = "none";
  } else {
    mybutton.style.display = "block";
  }
}
Edit
My bad, function was never called, but when hash changes, because of scrolling, button is not appearing, only after restart page. How to make it check if hash changes and execute function or smthing?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try it

window.addEventListener('hashchange', function() {
  //Your Function
}, false);

https://developer.mozilla.org/docs/Web/API/Window/hashchange_event

https://caniuse.com/?search=hashchange

about 4 years ago · Juan Pablo Isaza Denunciar

0

I found perfect script for this situation

mybutton = document.getElementById("scroll_top_button");

function locationHashChanged() {
  if (location.hash === "#firstPage") {
    mybutton.style.display = "none";
  } else {
    mybutton.style.display = "block";
  }
}

window.onhashchange = locationHashChanged;

But @Smith Charl helped me to find main logic to do this script tho

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda