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

96
Visualizações
Repostioning absolute position element based on a siblings change

I am working on some functionality where is user clicks a button it shows some "sub data" below a parent div. The markup looks similar to this,

<div class="row row-parent row-parent-index-1" style="top:20px">I am a parent (1)</div>
<div class="row" data-top="40px">I am a child (1)</div>
<div class="row" data-top="60px">I am a child (2)</div>
<div class="row" data-top="80px">I am a child (3)</div>
<div class="row row-parent row-parent-index-1" style="top:40px">I am a parent (2)</div>
<div class="row" data-top="top:40px">I am a child (1/2)</div>
<div class="row" data-top="top:60px">I am a child (2/2)</div>
<div class="row" data-top="80px">I am a child (3/2)</div>

Currently I have it working so that if a user clicks the row .row-parent-index-1 it takes the data-top attribute of all the elments between .row-parent-index-0and.row-parent-index-1and changes the top position to match that of thedata-top` the problem I need to reflect the change in all elements other wise I am going to get overlapping elements, if there a way to reposition absolute elements based on another elements position?

i.e if the element at index of 4 in the dom has top position of 80, we need to move all the following elements down 80px too?

Here is my attempt,

this.rowEl.addEventListener('click', (event) => {
    const target = event.currentTarget as HTMLElement;
    if(target.classList.contains("datagrid-parent-expanded")) {
      target.classList.remove('datagrid-parent-expanded');
    } else {
      target.classList.add('datagrid-parent-expanded');
      const indexOfCurrParent:any = parseInt(`${target?.dataset?.parentIndex}`);
      const targetClassList = target.classList.value;
      const siblings = helpers.nextUntil(document.querySelector(`.datagrid-main .datagrid-row-parent-index-${indexOfCurrParent}`), `.datagrid-main .datagrid-row-parent-index-${indexOfCurrParent+1}`);
      for (let rowIndex = 0; rowIndex < siblings.length; rowIndex++) {
        let currRow = siblings[rowIndex];
        currRow.style.setProperty("top", `${currRow.dataset.top}`);
        currRow.classList.add('datagrid-parent-expanded');
      }
      const nextSibling = siblings.pop().snextElementSibling as HTMLElement;
      const nextSiblingPosition = nextSibling.dataset.top!;
      nextSibling.style.top = parseInt(nextSiblingPosition, 10) + 20 + "px";
    }
  });

What I am trying to here is get the last element from the nextUntil function and take it's siblings position and add on the appropriate difference?

about 4 years ago · Juan Pablo Isaza
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