ItSolutionStuff.com

How to Create Custom Scrollbar using JQuery?

By Hardik Savani • June 23, 2023
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

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

JQuery Redirect to Another Page After 5 Seconds Example

Read Now →

How to Get Selected Checkbox Value from Checkboxlist using JQuery?

Read Now →

PHP MySQL DataTables Server-side Processing Example

Read Now →

How to Change Date Format in JQuery?

Read Now →

Bootstrap Show/Hide Toggle Password Input Field Example

Read Now →

How to Remove Comma from String in JQuery?

Read Now →

Bootstrap Multiple Select with Checkboxes using Bootstrap-multiselect.js JS

Read Now →

Bootstrap Fancy Alert Box using SweetAlert Example

Read Now →

Bootstrap Color Picker using Mjolnic Colorpicker Example

Read Now →

JQuery Timepicker with AM PM Format Example

Read Now →

JQuery Validate File Size with Multiple File Upload Example

Read Now →

JQuery Notification Popup Box using Toastr JS Example

Read Now →

JQuery Tag Input Plugin Example Code

Read Now →

JQuery Select Box with Search Option using Chosen Plugin

Read Now →