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

192
Visualizações
How to keep the element’s location when resizing the webpage

My goal is I'm trying to keep my element location when adjusting my browser and or changing to a larger display.

I have built a little sliding function that when I click each button my element .trans1 goes back and forth between the buttons.

The problem I'm having is my trans1 element goes off the button when resizing the browser, I hope that all makes sense and someone can help.

const tranImg= document.getElementById('trans');  

window.onload= trans;
// Make the trans move back and forth.
function trans(){
        console.log('test click')
        tranImg.style.transform = 'translatex(0%)';
        
        const xhr = new XMLHttpRequest();

        xhr.open("GET", "splash.html");
        
        xhr.onreadystatechange = () => {
            if(xhr.readyState === 4){
                document.querySelector(".app").innerHTML = xhr.response;
            }
        };
        
        xhr.send();
};

// Make the trans move back and forth.
function trans2(){
    console.log('hey trans2')
        tranImg.style.transform = 'translatex(180%)';

        const xhr = new XMLHttpRequest();

xhr.open("GET", "website.html");

xhr.onreadystatechange = () => {
    if(xhr.readyState === 4){
        document.querySelector(".app").innerHTML = xhr.response;
    }
};

xhr.send();
};
.trans-container {
  position: relative;
  top: 220px;
  width: 100%;
  height: auto;
}

#make-trans {
  display: flex;
  position: relative;
  width: 100%;
}

.trans1 {
  z-index: 980;
  margin-top: 3px;
  left: 11%;
  position: relative;
  top: 0.2px;
  transition: transform 0.8s;
}
 <div class="selectBtns">
        <button class="btns" id="btn2" onclick="trans()">Landing page</button>
        <button class="btns" onclick="trans2()">Website</button>
    </div>
    <div class="trans-container">
    <div id="make-trans">
        <img id="trans"  class="trans1" src="./images/svg-path (1).svg" alt="transition tab" width="400px">
    </div>
    <div class="xml-change">
        <div class="app"></div>
    </div>
</div>

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