Drag and Drop is a cool effect that can be used to create interesting and useful actions on a web page.
To create easily a drag and drop effect with jQuery, you need to use jQuery UI, which is a library of additional functions to the main jQuery library.
The jQuery UI is like a plugin that contains lots of functions to create special effects with jQuery. So, you need to include in your web page both jQuery library and jQuery UI.
- You can download jQuery UI from this page: Download jQuery UI
$('selector').draggable({ option: value });- option: value - represents one ore more option/value pairs that configure the draggable() function. There are lots of options for this function, here's some of them:
$('selector').droppable({ option: value });- option: value - represents one ore more option/value pairs that configure the droppable() method. Here's some of them:
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>jQuery Drag and Drop</title> <style type="text/css"><!-- #drop { width:200px; height:150px; margin:3px auto; background:#eddaa8; font-size:16px; } #drop #sw { text-decoration:underline; cursor:pointer; } #drag { width:450px; height:180px; margin:12px auto; border:1px solid silver; font-size:16px; } #drag .drg { margin:10px 12px; } #drag div.drg { width:150px; height:50px; background:#07da08; border:2px solid blue; } --></style> <script type="text/javascript" src="jquery_1.6.1.js"></script> <script type="text/javascript" src="jquery-ui-1.8.14.js"></script> <script type="text/javascript"><!-- $(document).ready(function() { // sets the draggable $('#drag .drg').draggable({ cursor: 'move', // sets the cursor apperance revert: 'valid' }); // sets droppable $('#drop').droppable({ drop: function(event, ui) { // after the draggable is droped, hides it with a hide() effect ui.draggable.hide(1000); } }); // when the "#sw" element (inside the "#drop") is clicked // show the items with class "drg", contained in "#drag" $('#drop #sw').click(function(){ $('#drag .drg').slideDown(1000); }); }); --></script> </head> <body> <div id="drop">Drop here <span id="sw">Show</span></div> <div id="drag"> Drag these images:<br /> <img src="circle.gif" alt="circle" width="45" height="45" class="drg" /> <img src="triangle.gif" alt="triangle" width="65" height="55" class="drg" /> <img src="rhomb.gif" alt="rhomb" width="70" height="55" class="drg" /> <div class="drg">DIV with some content. Click and drag</div> </div> </body> </html>Demo:
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>jQuery UI Drag and Drop</title> <style type="text/css"><!-- #drop { width:200px; height:150px; margin:3px auto; background:#eddaa8; font-size:16px; } #drop.drp { background:#f1ef08; } #drop #sw { text-decoration:underline; cursor:pointer; } #drag { width:450px; height:180px; margin:12px auto; border:1px solid silver; font-size:16px; } #drag .drg { margin:10px 12px; } #drag div.drg { width:150px; height:50px; background:#07da08; border:2px solid blue; } --></style> <script type="text/javascript" src="jquery_1.6.1.js"></script> <script type="text/javascript" src="jquery-ui-1.8.14.js"></script> <script type="text/javascript"><!-- $(document).ready(function() { // sets the draggable and define its options $('#drag .drg').draggable({ cursor: 'move', // sets the cursor apperance revert: 'invalid', // makes the item to return if it isn't placed into droppable revertDuration: 900, // duration while the item returns to its place opacity: 0.35 // opacity while the element is dragged }); // define options for droppable $('#drop').droppable({ accept: 'img.drg', // accept only images with class 'drg' activeClass: 'drp', // add class "drp" while an accepted item is dragged drop: function(event, ui) { // after the draggable is droped, hides it with a hide() effect ui.draggable.hide(1000); } }); // when the "#sw" element (inside the "#drop") is clicked // show the items with class "drg", contained in "#drag" $('#drop #sw').click(function(){ $('#drag .drg').slideDown(1000); }); }); --></script> </head> <body> <div id="drop">Drop here <span id="sw">Show</span></div> <div id="drag"> Drag these images:<br /> <img src="circle.gif" alt="circle" width="45" height="45" class="drg" /> <img src="triangle.gif" alt="triangle" width="65" height="55" class="drg" /> <img src="rhomb.gif" alt="rhomb" width="70" height="55" class="drg" /> <div class="drg">DIV with some content. Click and drag</div> </div> </body> </html>- revert: 'invalid' - makes the element to return to its position if it isn't placed into droppable; and - evertDuration: 900 - sets the duration of the return to 900 milliseconds.
<table><tr> <th>Title 1</th> <th>Title 2</th> </tr></table>
.some_class { line-height: 150%; }
document.getElementById("id_button").onclick = function(){ window.open("http://coursesweb.net/"); }
$ar_dir = scandir("dir_name"); var_export($ar_dir);