How to Create Custom Scrollbar using JQuery?

By Hardik Savani June 23, 2023 Category : 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...

Shares