JavaScript - Dynamic Image Reorder

In this tutorial we will create a Dynamic Image Reorder using JavaScript. This code can move and reorder the object in any posiiton at the same time. It use jQuery-UI to implement the feature in order to rearrange the image order. This is a user-friendly program feel free to modify it. We will use jQuery-UI as a curated set of user interface interactions that built in jQuery, a JavaScript Library that consist of different widgets. It is highly interactive web applications that just needed to add a widget to make a certain script works.

Getting Started:

This is the link for the bootstrap that i used for the layout design https://getbootstrap.com/. And this is the link for the jquery that i used in this tutorial https://jquery.com/. Lastly, this is the link for the jQuery-UI that I used https://jqueryui.com/.

The Main Interface

This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.         <head>
  4.                 <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" />
  5.                 <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  6.                 <link rel="stylesheet" type="text/css" href="css/jquery-ui.css"/>
  7.                  <style>
  8.                         #images {
  9.                                 list-style-type: none;  
  10.                         }
  11.                         #images li {
  12.                                 margin:5px;
  13.                                 float: left;
  14.                                 width: 180px;
  15.                                 height: 180px;
  16.                                 font-size: 4em;
  17.                                 text-align: center;
  18.                                 cursor:pointer;
  19.                         }
  20.                 </style>
  21.         </head>
  22.         <nav class="navbar navbar-default">
  23.                 <div class="container-fluid">
  24.                         <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
  25.                 </div>
  26.         </nav>
  27.         <div class="col-md-3"></div>
  28.         <div class="col-md-6 well">
  29.                 <h3 class="text-primary">JavaScript - Dynamic Image Reorder</h3>
  30.                 <hr style="border-top:1px dotted #ccc;"/>
  31.                 <ul id="images">
  32.                         <li class="ui-state-default"><img src="images/image1.gif"  height="100%"width="100%"/></li>
  33.                         <li class="ui-state-default"><img src="images/image2.jpg"  height="100%"width="100%"/></li>
  34.                         <li class="ui-state-default"><img src="images/image3.jpg"  height="100%"width="100%"/></li>
  35.                         <li class="ui-state-default"><img src="images/image3.jpg"  height="100%"width="100%"/></li>
  36.                         <li class="ui-state-default"><img src="images/image1.gif"  height="100%"width="100%"/></li>
  37.                         <li class="ui-state-default"><img src="images/image2.jpg"  height="100%"width="100%"/></li>
  38.                 </ul>
  39.         </div>
  40. <script src="js/jquery-3.2.1.min.js"></script>
  41. <script src="js/jquery-ui.js"></script>
  42. <script src="js/script.js"></script>
  43. </body>
  44. </html>

Creating the Script

This code contains the script of the application. This code can reorder the image position by dragging. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js directory
  1. $(document).ready(function(){
  2.         $( "#images" ).sortable();
  3.         $( "#images" ).disableSelection();
  4. });
There you have it we successfully created a Dynamic Image Reorder using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

Add new comment