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

230
Views
How to remove and add class on scroll JavaScript

const scrollList = document.getElementsByClassName('scrollList');


function scrollLeft() {
    scrollList.scrollLeft -= 50
}

function scrollRight() {
    scrollList.scrollLeft += 50
}
#scrollList {
  display: flex;
  overflow: auto;
  width: 100px;
}

.div {
  display: flex;
}
<div class="div">
  <button onclick="scrollLeft()">Scroll Left</button>
    <div id="scrollList">
    <p>Image</p>
    <p>Image</p>
    <p>Image</p>
    <p>Image</p>
    <p>Image</p>
    <p>Image</p>
    </div>
<button  onclick="scrollRight()">Scroll Right</button>
</div>

I have a Horizontal page scroll on div with arrows and I want to hide the left and right arrow when you can't scroll more. I have an gallery so when there is no more images to scroll to I want to hide the button(arrow). So in the beginning I dont want to show the left arrow, and in the end when there is no more images I want to hide the right arrow. How can I do that with javascript? Thanks for your help!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Let me answer my friend. It might help you. ^_^

<!DOCTYPE html>
<html>
<head>
<style>
.example {
  background-color: #eee;
  width: 200px;
  height: 100px;
  border: 1px dotted black;
  overflow-y: scroll; /* Add the ability to scroll */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.example::-webkit-scrollbar {
    display: none;
}

/* Hide scrollbar for IE, Edge and Firefox */
.example {
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;  /* Firefox */
}
</style>
</head>
<body>

<h2>Hide scrollbar but keep functionality</h2>
<p>Try to scroll inside the div below:</p>

<div class="example">Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. Some text to enable scrolling.. </div>

</body>
</html>

about 4 years ago · Juan Pablo Isaza Report

0

You can use window.scroll() function in JavaScript Let xScroll=window.scrollX Its return float value and then use conditions to show arrow " ClassName={xScroll<70 ? 'hide' : 'show'}

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!