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

244
Visualizações
Disable scroll button until fully scrolled

https://codepen.io/ha26ktan/pen/oNoQGEO

I built a website with my minimal - intermediate level of css and html knowledge. I have 2 buttons. One of them is for scrolling to the right and the other to the left. This scrolling is according to the width of a divin column.

When the right or left button is pressed repeatedly, the command is triggered again without waiting for the distance to go, and this causes it to stay outside the required distance.

How can I disable both buttons until they switch to the other column? Thank you very much in advance.

`const kitapp = document.getElementById('kitapp');

document.getElementById("btnLeft").onclick = () => {
  kitapp.scroll({
    left: kitapp.scrollLeft + kitapp.querySelector(".deneme").offsetWidth,
    behavior: 'smooth'
  });
}
     
document.getElementById("btnRight").onclick = () => {
  kitapp.scroll({
    left: kitapp.scrollLeft - kitapp.querySelector(".deneme").offsetWidth,
    behavior: 'smooth'
  });
}`

const kitapp = document.getElementById('kitapp');

document.getElementById("btnRight").onclick = () => {
document.getElementById("btnRight").disabled = true;
  kitapp.scroll({
    left: kitapp.scrollLeft + kitapp.querySelector(".deneme").offsetWidth,
    behavior: 'smooth'
  });
setTimeout(enableButon1, 1000);

}
 
document.getElementById("btnLeft").onclick = () => {
document.getElementById("btnRight").disabled = true;
  kitapp.scroll({
    left: kitapp.scrollLeft - kitapp.querySelector(".deneme").offsetWidth,
    behavior: 'smooth'
  });
setTimeout(enableButon2, 1000);
  
}

function enableButon1() {
     document.getElementById("btnLeft").disabled = false;
}
function enableButon1() {
    document.getElementById("btnRight").disabled = false;
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can try to disable the button once you click on it, you can use

document.getElementById("btnLeft").disabled = true;

once you click on it. It can look like this:

const kitapp = document.getElementById('kitapp');

document.getElementById("btnLeft").onclick = () => {
  kitapp.scroll({
    left: kitapp.scrollLeft + kitapp.querySelector(".deneme").offsetWidth,
    behavior: 'smooth'
  });
document.getElementById("btnLeft").disabled = true;
}
 
document.getElementById("btnRight").onclick = () => {
  kitapp.scroll({
    left: kitapp.scrollLeft - kitapp.querySelector(".deneme").offsetWidth,
    behavior: 'smooth'
  });
  document.getElementById("btnRight").disabled = true;
}

I think this should work for you, but you will need to enable the button later, making a timer for example, or enabling it when you click the other button.

about 4 years ago · Juan Pablo Isaza Relatório

0

Then you can try to make like this: When you click on the button, you can disable it

const kitapp = document.getElementById('kitapp');

document.getElementById("btnLeft").onclick = () => {
document.getElementById("btnLeft").disabled = true;
  kitapp.scroll({
    left: kitapp.scrollLeft + kitapp.querySelector(".deneme").offsetWidth,
    behavior: 'smooth'
  });
setTimeout(enableButon1, 1000);

}
 
document.getElementById("btnRight").onclick = () => {
document.getElementById("btnRight").disabled = true;
  kitapp.scroll({
    left: kitapp.scrollLeft - kitapp.querySelector(".deneme").offsetWidth,
    behavior: 'smooth'
  });
setTimeout(enableButon2, 1000);
  
}

function enableButon1() {
     document.getElementById("btnLeft").disabled = false;
}
function enableButon1() {
    document.getElementById("btnRight").disabled = false;
}

I hope this one works for you.

You can change the time it waits changing the value of setTimeout(enableButon2, 1000); and put the number you want to wait.

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