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 implemented a horizontal page scroll layout with buttons for scrolling left and right within a div element. However, I am looking to dynamically hide the left and right scroll buttons when reaching the boundaries of the content. Specifically, I would like to hide the left button when starting from the beginning of the gallery, and hide the right button when there are no more images to scroll towards. How can I achieve this behavior using javascript?