JSFiddle - React, Tailwind, and code Playground
by pphheerroonn
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Horizontal Scroll Button</title>
<style>
.scroll-container {
width: 300px;
height: 100px;
overflow-x: auto;
white-space: nowrap;
border: 1px solid #ccc;
padding: 10px;
}
.content {
display: inline-block;
width: 1000px;
height: 100px;
background: linear-gradient(to right, #f06, #4a90e2);
}
.scroll-button {
margin: 20px 0;
}
</style>
</head>
<body>
<button class="scroll-button" onclick="scrollDiv()">Scroll Right</button>
<div class="scroll-container" id="scrollContainer">
<div class="content"></div>
</div>
<script>
function scrollDiv() {
const container = document.getElementById('scrollContainer');
container.scrollBy({
left: 100, // Adjust this value to control the scroll distance
behavior: 'smooth' // Optional for smooth scrolling
});
}
</script>
</body>
</html>