I’m struggling with this process and nothing so far….
I have a div with custom scrollbar what i am trying is when the div is less than 196px the scrollbar i want to be removed and if is more then 196px the scroll to appear. Sorry for my bad English, and thanks for any support!
$(".scrollbar").scroll(function() {
var h = this.innerHeight;
if (h > 100) {
$(".cstm").addClass("scrollbar");
} else {
$('.cstm').removeClass("scrollbar");
}
});
.scrollbar {
height: 196px;
overflow-y: scroll;
padding: 4px;
}
#style-3::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
background-color: red;
}
#style-3::-webkit-scrollbar {
width: 4px;
background-color: #F5F5F5;
}
#style-3::-webkit-scrollbar-thumb {
background-color: #000000;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<div class="cstm scrollbar" id="style-3" style="display: block;">
<div class="my-box">
<div class="animated slideInUp" style="margin-bottom: -22px;font-size: 12px;background: #f5f5f5;color: #e60000;border-radius: 3px;padding: 2px;">
<center>
<i class="animated flash fa fa-times-circle"></i> INFO BOX 1
</center>
</div><br>
<div class="animated slideInUp" style="margin-bottom: -22px;font-size: 12px;background: #f5f5f5;color: #e60000;border-radius: 3px;padding: 2px;">
<center>INFO BOX 2 </center>
</div><br>
<div class="animated slideInUp" style="margin-bottom: -22px;font-size: 12px;background: #f5f5f5;color: #e60000;border-radius: 3px;padding: 2px;">
<center> ON FEW BOXES THE RED SCROLL TO BE REMOVED</center>
</div><br>
</div>
</div>
4
Answers
Which browser are you currently testing? I tried running the example on your src with chrome and it seems to work
Try this:
You should have a limited height and
overflow-y
is hidden.Also you should define scroll bar width like above code.
Hope it helps.
You could try instead of just removing the scrollbar class to add a class that explicitly states no-scrollbar:
Ok. I achived what you need using setInterval funcion. Setintervalfunction executes its statments continuously. When the height is higher than 100px. it add de class. Else its removes it.
You can check this behavior in my snippet.
Hope it helps