Getting Started with EJ2 JavaScript Range Slider
21 Nov 20264 minutes to read
This section explains the steps required to create a simple Essential® JS 2 Range Slider and demonstrate the basic usage of the Range Slider control in a JavaScript application.
Dependencies
The list of dependencies required to use the Range Slider component in your application is given below:
|-- @syncfusion/ej2-inputs
|-- @syncfusion/ej2-baseSetup for local environment
Refer to the following steps to set up your local environment.
Step 1: Create a root folder named my-app for your application.
Step 2: Create a my-app/resources folder to store local scripts and styles files.
Step 3: Open Visual Studio Code and create my-app/index.js and my-app/index.html files to initialize the Essential® JS 2 Range Slider control.
Control Initialization
The Essential® JS 2 JavaScript controls can be initialized by using below css styles and Scripts
Add Syncfusion® Slider CSS Styles and Scripts
Include the following CSS and JavaScript files from CDN in the <head> section of the index.html file. The ej2-base scripts are required dependency packages for the Slider component.
Styles(CSS):
https://unpkg.com/@syncfusion/ej2-bootstrap5.3-theme/styles/slider/index.cssScripts (javascript):
https://cdn.syncfusion.com/ej2/35.1.37/ej2-base/dist/global/ej2-base.min.js
https://cdn.syncfusion.com/ej2/35.1.37/ej2-inputs/dist/global/ej2-inputs.min.jsAdding Slider component to the application
Add the Slider element and initialize the Essential® JS 2 Range Slider control in the index.html file by using the following code.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Essential JS 2 Range Slider control</title>
<!-- Essential JS 2 bootstrap5.3 theme -->
<link href="https://unpkg.com/@syncfusion/ej2-bootstrap5.3-theme/styles/slider/index.css" rel="stylesheet" />
<!-- Essential JS 2 Input's global script -->
<script src="https://cdn.syncfusion.com/ej2/35.2.12/ej2-base/dist/global/ej2-base.min.js"
type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/35.2.12/ej2-buttons/dist/global/ej2-buttons.min.js"
type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/35.2.12/ej2-popups/dist/global/ej2-popups.min.js"
type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/35.2.12/ej2-inputs/dist/global/ej2-inputs.min.js"
type="text/javascript"></script>
</head>
<body>
<div class='wrap'>
<!-- Add the HTML <div> element -->
<div id='element'></div>
</div>
<script>
// Initialize Essential JS 2 JavaScript Slider control
var sliderInstance = new ej.inputs.Slider({ value: 30 });
//Render initialized Range Slider Control
sliderInstance.appendTo("#element");
</script>
<style>
.wrap {
box-sizing: border-box;
height: 140px;
margin: 100px auto;
padding: 30px 10px;
}
</style>
</body>
</html>#container {
visibility: hidden;
}
#loader {
color: #008cff;
font-family: 'Helvetica Neue','calibiri';
font-size: 14px;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}