SortableJS is a modern, lightweight, and customizable library that allows you to reorder lists and grids using drag-and-drop functionality. This section covers the steps required to include SortableJS in your project:
To install SortableJS, run the following command in the root directory of your project:
yarn add sortablejs --save
To use SortableJS in your project, you need to include its JavaScript file in your HTML:
<script src="assets/libs/sortablejs/Sortable.min.js"><script/>
Below is an example of the HTML code to create a sortable list using SortableJS. Users can drag-and-drop the list items to reorder them:
- Item 1
- Item 2
- Item 3
- Item 4
Here is the JavaScript code that initializes the SortableJS instance. This will enable the drag-and-drop functionality for the list:
const sortable = new Sortable(document.getElementById('sortableList'), { animation: 150, // Smooth animation for the drag-and-drop action ghostClass: 'sortable-ghost', // Class for the dragged item dragClass: 'sortable-drag', // Class for the item being dragged });
The above JavaScript code does the following:
Be the first to know about new updates and exclusive discounts. No spam, just great offers!
How about
With over 7 years of experienced team, we specialize in delivering custom projects for startups, blue-chip companies, and government agencies. We have successfully completed over 250+ projects, providing tailored solutions that meet the unique needs of each client.
Support© Herozi Design & Develop by Codebucks.