To create easily a drag 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:
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>jQuery UI Dragging</title> <style type="text/css"><!-- #dg2 { width:180px; height:100px; margin:8px; background:#a7daa8; } --></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 '#dg1' element as draggable and define some options $('#dg1').draggable({ cursor: 'move', // sets the cursor apperance opacity: 0.35, // opacity fo the element while it's dragged stack: $('#dg1') // brings the '#dg1' item to front }); // sets the '#dg2' element as draggable $('#dg2').draggable({ cursor: 'pointer', // sets the cursor apperance opacity: 0.35, // opacity fo the element while it's dragged stack: $('#dg2'), // brings the '#dg2' item to front axis: 'x' // allow dragging only on the horizontal axis }); }); --></script> </head> <body> <h4>Click and drag:</h4> <img src="rhomb.gif" alt="Rhomb" width="80" height="70" id="dg1" /> <div id="dg2">Draggable only on horizontal axis,<br /> Cursor sets to pointer.</div> </body> </html>Demo:
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>jQuery UI Dragging with revert</title> <style type="text/css"><!-- div.dg { width:180px; height:100px; margin:8px; background:#a7daa8; } --></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 elements with class="dg" as draggable and define some options $('.dg').draggable({ cursor: 'move', // sets the cursor apperance opacity: 0.35, // opacity fo the element while it's dragged revert: true, // sets the element to return to its start location revertDuration: 900 }); // sets another option (cursorAt), but only for DIV with class="dg" $('div.dg').draggable({ cursorAt: {left: 8} }); }); --></script> </head> <body> <h4>Click and drag:</h4> <img src="rhomb.gif" alt="Rhomb" width="80" height="70" class="dg" /> <div class="dg">DIV draggable with revert.<br /> Cursor bringed to left side.</div> </body> </html>Demo:
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>jQuery UI Dragging with handle</title> <style type="text/css"><!-- #dg { width:225px; border:1px solid blue; } #dg h5 { margin:1px; background:#07da08; cursor:pointer; text-decoration:underline; text-align:center; } #dg p { margin:10px 3px 0px 3px; background:#d7d8fe; } --></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 draggable the elements with id="dg" $('#dg').draggable({ // sets to can be dragged only when the cursor is over the H5 part handle: 'h5' }); }); --></script> </head> <body> <div id="dg"> <h5>Click and Drag</h5> <p>jQuery Course:<br /> <i>https://coursesweb.net/javascript/</i></p> </div> </body> </html>Demo:
jQuery Course:
https://coursesweb.net/javascript/
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>jQuery UI Dragging with containment</title> <style type="text/css"><!-- #drg { width:380px; height:210px; border:2px solid blue; } #prt { width:305px; height:100px; margin:8px; background:#efefef; } #prt p { width:185px; margin:1px; background:#a7daa8; } --></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 draggable the elements with id="im" $('#im').draggable({ cursor: 'move', // sets the cursor apperance containment: '#drg' // sets to can be dragged only within "#drg" element }); // sets draggable the paragraph inside #prt $('#prt p').draggable({ cursor: 'move', containment: 'parent' // sets to can be dragged only within its parent }); }); --></script> </head> <body> <h4>Click and drag:</h4> <div id="drg"> #drg box<br /> <img src="rhomb.gif" alt="Rhomb" width="80" height="70" id="im" /> <div id="prt"> <p>This paragraph can be dragged only inside its parent</p> </div> </div> </body> </html>Demo:
This paragraph can be dragged only inside its parent
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>jQuery UI Dragging - get direction and distance</title> <style type="text/css"><!-- #dg { width:180px; height:100px; margin:8px; background:#a7daa8; cursor:pointer; } --></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"><!-- // sets two variables to store the X and Y position var xpos; var ypos; $(document).ready(function() { // sets draggable the element with id="dg" $('#dg').draggable({ // get the initial X and Y position when dragging starts start: function(event, ui) { xpos = ui.position.left; ypos = ui.position.top; }, // when dragging stops stop: function(event, ui) { // calculate the dragged distance, with the current X and Y position and the "xpos" and "ypos" var xmove = ui.position.left - xpos; var ymove = ui.position.top - ypos; // define the moved direction: right, bottom (when positive), left, up (when negative) var xd = xmove >= 0 ? ' To right: ' : ' To left: '; var yd = ymove >= 0 ? ' Bottom: ' : ' Up: '; alert('The DIV was moved,\n\n'+ xd+ xmove+ ' pixels \n'+ yd+ ymove+ ' pixels'); } }); }); --></script> </head> <body> <div id="dg">Click and Drag<br /> Will alert the X and Y moved direction and distance.</div> </body> </html>Demo:
<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);