"Custom Horizontal Scroll Button JavaScript"
Bootstrap 4.1.1 Snippet by mdwaris198

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container mt-5">
<div class="bg-light p-3" id="content">
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
</div>
<div class="mt-4">
<button class="btn btn-danger" onclick="scrollLeft2()" >Prev</button>
<button class="btn btn-danger" onclick="scrollRight()" >Next</button>
</div>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
*{
box-sizing: border-box;
margin: 0;
padding: 0;
}
#content{
display: flex;
width: 600px;
overflow-x: scroll;
scroll-behavior: smooth;
}
#content p{
padding: 30px;
background: darkgreen;
color:#fff;
margin-right:15px;
border-radius:10px;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
// scroll button
function scrollLeft2(){
document.getElementById('content').scrollLeft -=300;
}
function scrollRight(){
document.getElementById('content').scrollLeft +=300;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: