Scrollable Content Div with jQuery
StackOverflow Example
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
<script src="https://use.fontawesome.com/d008e6c4be.js"></script>
<div id="container">
<p id="content">a quick brown fox jumps over the lazy dog a quick brown fox jumps over the lazy dog</p>
<i id="left" class="fa fa-chevron-left" aria-hidden="true"></i>
<i id="right" class="fa fa-chevron-right" aria-hidden="true"></i>
</div>
<p id="info"></p>
CSS
#container {
position: relative;
background-color: #C0EB8F;
width: 250px;
height: 30px;
overflow: hidden;
white-space: nowrap;
}
#container > p {
margin: 0;
position: absolute;
top: 10%;
}
#left,
#right {
margin: 0;
font-size: 18px;
cursor: pointer;
position: absolute;
top: 0;
background-color: rgba(192,235,143, 1);
color: rgb(170,170,170);
padding: 6px 2px;
}
#left {
left: 0;
}
#right {
right: 0;
}
JavaScript
var x = $("#container").offset();
var y = $("#content").offset();
if (y.left === x.left) {
$("#left").hide();
}
$("#left").mousedown(function() {
var y = $("#content").offset();
$("#content").animate({
left: 0
}, function callback() {
$("#left").fadeOut();
});
});
$("#right").mousedown(function() {
var y = $("#content").offset();
$("#left").show();
$("#content").animate({
left: y.left - 200
});
$("#info").text(y.left - 100);
});