jQuery - Interaction Drag-able


Advertisements

Description

The Drag-able function can be used with interactions in JqueryUI.This function can enable drag-able functionality on any DOM element.We can drag the drag-able element by clicking on it with mouse.

Syntax

Here is the simple syntax to use drag-able −

 $( "#draggable" ).draggable();

Example

Following is a simple example showing the usage of drag-able −

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js">
      </script>
		
      <script type = "text/javascript" language = "javascript">
   
         $(function() {
            $( "#draggable" ).draggable();
         });
		 
      </script>
		
      <style>
         #draggable { width: 150px; height: 150px; padding: 0.5em; }
         .back{
            background-color: lightgrey;
            width: 50px;
            padding: 25px;
            border: 25px solid navy;
            margin: 25px;
         }
      </style>
   </head>
	
   <body>
      <div id = "draggable" class = "ui-widget-content">
         <p class = "back">Drag</p>
      </div>
	 
   </body>
</html>

This will produce following result −

jquery-interactions.htm
Advertisements