POC Scroll 20180307
Version 1.5: arrow hide show working js
by ced1
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<i class="fa fa-caret-up arrow-scroll arrow-scroll-top" id="GotoTopPraticiens" aria-hidden="true"></i>
<div id="scrollbox-blankTop"></div>
<div class="scrollbox-outer">
<div class="scrollbox-inner" id="box">
<div class="element">
<ul class="list-unstyled">
<div class="container">
<div class="row">
<div class="col-sm-6"><li class="media-item"></li></div>
<div class="col-sm-6"><li class="media-item"></li></div>
<div class="col-sm-6"><li class="media-item"></li></div>
<div class="col-sm-6"><li class="media-item"></li></div>
<div class="col-sm-6"><li class="media-item"></li></div>
<div class="col-sm-6"><li class="media-item"></li></div>
<div class="col-sm-6"><li class="media-item"></li></div>
<div class="col-sm-6"><li class="media-item"></li></div>
<div class="col-sm-6"><li class="media-item"></li></div>
<div class="col-sm-6"><li class="media-item"></li></div>
<div class="col-sm-6"><li class="media-item"></li></div>
<div class="col-sm-6"><li class="media-item"></li></div>
</div>
</div>
</ul>
</div>
</div>
</div>
<i class="fa fa-caret-down arrow-scroll arrow-scroll-bottom" id="GotoBottomPraticiens" aria-hidden="true"></i>
<div id="scrollbox-blankBottom"></div>
CSS
.media-item {
position: relative;
border: 1px solid #b0b0b0;
margin: 7px;
width: 350px;
color: #b0b0b0;
/*font-weight: bold;*/
font-size: 18px;
height: 155px;
padding: 30px 0px;
padding-left: 32px;
/* background-color:red; */
}
.element, .scrollbox-outer {
width: 850px;
height: 800px;
}
.scrollbox-outer {
border: 5px solid purple;
position: relative;
overflow: hidden;
}
.scrollbox-inner {
position: absolute;
left: 0;
overflow-x: hidden;
overflow-y: scroll;
}
.scrollbox-inner::-webkit-scrollbar {
display: none;
}
/* font awesome */
.arrow-scroll{
/*display arrows*/
color: #8d6dc4;
font-size: 50px;
font-weight: bold;
/*center the arrows*/
display: flex;
justify-content: center;
align-items: center;
}
#scrollbox-blankTop{
height: 50px;
}
#debug{
height: 50px;
background:red;
}
JavaScript
$("#GotoTopPraticiens").hide();
$("#scrollbox-blankBottom").hide();
$("#GotoTopPraticiens").on("click", function() {
$(".scrollbox-inner").scrollTop(0);
$("#GotoTopPraticiens").hide();
$("#scrollbox-blankTop").show();
$("#GotoBottomPraticiens").show();
$("#scrollbox-blankBottom").hide();
});
$("#GotoBottomPraticiens").on("click", function() {
$(".scrollbox-inner").scrollTop(300);
$("#GotoBottomPraticiens").hide();
$("#scrollbox-blankBottom").show();
$("#GotoTopPraticiens").show();
$("#scrollbox-blankTop").hide();
});
document.getElementById('box').addEventListener('scroll', function()
{
var scrollTop = document.getElementById('box').scrollTop;
var scrollHeight = document.getElementById('box').scrollHeight; // added
var offsetHeight = document.getElementById('box').offsetHeight;
// var clientHeight = document.getElementById('box').clientHeight;
var contentHeight = scrollHeight - offsetHeight;
if (contentHeight <= scrollTop)
{
// Called when scroll end at bottom
$("#scrollbox-blankTop").hide();
$("#GotoTopPraticiens").show();
$("#GotoBottomPraticiens").hide();
$("#scrollbox-blankBottom").show();
}
else if(scrollTop == 0)
{
// Called when scroll end at top
$("#GotoTopPraticiens").hide();
$("#scrollbox-blankTop").show();
$("#GotoBottomPraticiens").show();
$("#scrollbox-blankBottom").hide();
}
else if(contentHeight >= scrollTop)
{
// Called when scrolling
$("#GotoTopPraticiens").show();
$("#scrollbox-blankTop").hide();
$("#GotoBottomPraticiens").show();
$("#scrollbox-blankBottom").hide();
}
},
false
)