Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!