How to Create Custom Scrollbar using JQuery?
In this post, we will learn how to make custom scrollbar will better layout using jquery.mcustomscrollbar plugin. We always want to make best layout of scrollbar instead of default browser layout. default browser layout scrollbar always deferent layout because it depend of browser. So today in this post you can see how to make pretty beautifully scrollbar using mcustomscrollbar plugin. mcustomscrollbar plugin provide us several other option to make more better like set theme and options.
So here i make very simple example using mcustomscrollbar cdn, you can see layout of example and also you can simply run bellow full example. So you can simply use mcustomscrollbar plugin with different theme like as bellow:
(function($){
$(window).on("load",function(){
$(".my-scroll").mCustomScrollbar({theme:"dark-3"});
});
})(jQuery);
Bellow you can see the preview of this example:
Preview:
Example:
<!DOCTYPE html>
<html>
<head>
<title>Custom Scrollbar Example</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.5/jquery.mCustomScrollbar.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.5/jquery.mCustomScrollbar.min.js"></script>
<style type="text/css">
.my-scroll{
border:1px solid #e1e1e1;
height: 200px;
width:400px;
overflow-y: auto;
}
</style>
</head>
<body>
<div class="container">
<br/>
<h2>Custom scrollbar using jquery mcustomscrollbar Plugin</h2>
<br/>
<div class="my-scroll">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
<script>
(function($){
$(window).on("load",function(){
$(".my-scroll").mCustomScrollbar({theme:"dark-3"});
});
})(jQuery);
</script>
</body>
</html>
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- JQuery Redirect to Another Page After 5 Seconds Example
- How to Get Selected Checkbox Value from Checkboxlist using JQuery?
- PHP MySQL DataTables Server-side Processing Example
- How to Change Date Format in JQuery?
- Bootstrap Show/Hide Toggle Password Input Field Example
- How to Remove Comma from String in JQuery?
- Bootstrap Multiple Select with Checkboxes using Bootstrap-multiselect.js JS
- Bootstrap Fancy Alert Box using SweetAlert Example
- Bootstrap Color Picker using Mjolnic Colorpicker Example
- JQuery Timepicker with AM PM Format Example
- JQuery Validate File Size with Multiple File Upload Example
- JQuery Notification Popup Box using Toastr JS Example
- JQuery Tag Input Plugin Example Code
- JQuery Select Box with Search Option using Chosen Plugin