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

96
Vistas
Window/Screen Collapsible bottom follow

I am trying to get my screen to follow my collapsible when opening it. My content is hidden under the collapsible and i tried it with window.scrollTo() already, but my script is only getting the current location of my bottom footer which it has when i am pressing the button.

enter image description here


Edit:
My Code Snippet: https://jsfiddle.net/jz961rL0/2/
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I was able to make this work using an ResizeObserver. I've assigned an id to your collapible container for simplicities sake, so I can query it easier, then assigned an oberserver to it, and everytime the dimension changes, it will scrollIntoView():

// https://www.w3schools.com/howto/howto_js_collapsible.asp
var coll = document.getElementsByClassName("collapsible");
var i;

let collapsibleContainer = document.getElementById("container");

let resizeObserver = new ResizeObserver(entries => {
  // make sure entries only ever contains one element.
  // scrolling to multiple elements simultanously might yield
  // interesting results.
  for(let entry of entries) {
    collapsibleContainer.scrollIntoView()
  }
});

resizeObserver.observe(collapsibleContainer);

for (i = 0; i < coll.length; i++) {
  coll[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var content = this.nextElementSibling;
    if (content.style.maxHeight){
        content.style.maxHeight = null;

    } else {
        content.style.maxHeight = content.scrollHeight + "px";
    } 
  });
}

Html:

<button class="collapsible">      
  <div class="wrapper">
    <h1 class="headline">collapsible</h1>
  </div>
</button>   
<div class="content-collapse" id="container">
    <!-- Rest omitted -->
</div>

ResizeObserver is not supported by Internet Explorer, but fingers crossed, that you are not required to support that plattform

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