Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda