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

254
Vistas
How to combine dynamic Javascript div height resizing with in-page anchor hyperlinks?

Ok, this is an unusual question, but I've been playing around with it for hours and haven't had any progress - hoping the SO community can help! 🤓

Here's the webpage in question: https://pifornerds.io/

We're using this code to dynamically set the background (the digits of pi that you see in grey) height based on the foreground content length:

<script>
      // Dynamically set base height based on container contents
      var containerHeight = document.getElementById("container").offsetHeight;
      var baseHeight = document.getElementById("base").offsetHeight;
      if (baseHeight > containerHeight) {
        document.getElementById("base").style.height = containerHeight + "px";
      }
</script>

CSS snippet:

.layered {
  display: grid;
  justify-items: left;
  background-color: #222222;
  max-width: 1000px;
  margin: auto;
  height: auto;
  min-height: 100px;
  overflow: hidden;
}

.layered > * {
  grid-column-start: 1;
  grid-row-start: 1;
}

.base {
  font-family: "DejaVuSansMonoBold", courier;
  color: white;
  opacity: 0.1;
  max-width: 100%;
  height: 100%;
  word-break: break-all;
  margin-top: -3px;
  margin-left: 10px;
  margin-right: 10px;
  margin-bottom: 10px;
  position: static;
  z-index: 1;
  overflow: hidden;
}

.container {
  display: block;
  height: max-content;
  overflow: hidden;
}

We wanted to do this so there wouldn't be a bunch of pi digits in the footer area. We think it looks "cleaner" this way.

However, the menu at the top uses anchor links to jump to content lower on the page, for example:

<a href="#roadmap">Roadmap</a>

jumps to:

<a id="roadmap"></a>

Now here's the problem ...

After you click a menu anchor link, and then try to scroll back up the page to the top, you can't 🧐 ... because somehow the previous Javascript height update won't allow that.

This is as far up as I can scroll up now, after clicking "Roadmap":

enter image description here

Any ideas? Thanks in advance! 😀

EDIT: Here's a Fiddle: https://jsfiddle.net/imkane/kof83msy/4/ Of course it works properly there 😖

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

0

You need to remove the overflow: hidden; from .layered div. It will probably be better to add overflow: hidden; to .base div, which is the one you set the height on.

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