mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
75 lines
2.4 KiB
HTML
75 lines
2.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>jQuery UI Draggable - Cursor style</title>
|
|
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
|
|
<script src="../../jquery-1.7.1.js"></script>
|
|
<script src="../../ui/jquery.ui.core.js"></script>
|
|
<script src="../../ui/jquery.ui.widget.js"></script>
|
|
<script src="../../ui/jquery.ui.interaction.js"></script>
|
|
<script src="../../ui/jquery.ui.draggable.js"></script>
|
|
<link rel="stylesheet" href="../demos.css">
|
|
<style>
|
|
#draggable, #draggable2, #draggable3 { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 0 10px 10px 0; }
|
|
</style>
|
|
<script>
|
|
$.ui.draggable.prototype.options.cursorAt = null;
|
|
$( document ).bind( "dragbeforestart", function( event, ui ) {
|
|
var cursorAt, elem,
|
|
draggable = $( event.target ).data( "draggable" );
|
|
|
|
if ( !draggable || !draggable.options.cursorAt ) {
|
|
return;
|
|
}
|
|
|
|
elem = ui.helper || draggable.element;
|
|
cursorAt = draggable.options.cursorAt;
|
|
if ( "top" in cursorAt ) {
|
|
ui.position.top += ui.pointer.y - ui.offset.top - cursorAt.top;
|
|
}
|
|
if ( "left" in cursorAt ) {
|
|
ui.position.left += ui.pointer.x - ui.offset.left - cursorAt.left;
|
|
}
|
|
if ( "bottom" in cursorAt ) {
|
|
ui.position.top += ui.pointer.y - ui.offset.top - elem.outerHeight() + cursorAt.bottom;
|
|
}
|
|
if ( "right" in cursorAt ) {
|
|
ui.position.left += ui.pointer.x - ui.offset.left - elem.outerWidth() + cursorAt.right;
|
|
}
|
|
});
|
|
|
|
$(function() {
|
|
$( "#draggable" ).draggable({ cursorAt: { top: 56, left: 56 } });
|
|
$( "#draggable2" ).draggable({ cursorAt: { top: -5, left: -5 } });
|
|
$( "#draggable3" ).draggable({ cursorAt: { bottom: 0 } });
|
|
});
|
|
</script>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="demo">
|
|
|
|
<div id="draggable" class="ui-widget-content">
|
|
<p>I will always stick to the center (relative to the pointer)</p>
|
|
</div>
|
|
|
|
<div id="draggable2" class="ui-widget-content">
|
|
<p>My cursor is at left -5 and top -5</p>
|
|
</div>
|
|
|
|
<div id="draggable3" class="ui-widget-content">
|
|
<p>My cursor position is only controlled for the 'bottom' value</p>
|
|
</div>
|
|
|
|
</div><!-- End demo -->
|
|
|
|
|
|
|
|
<div class="demo-description">
|
|
<p>Position the cursor while dragging the object. By default the cursor appears wherever the user started the drag; use the <code>cursorAt</code> option to specify another location relative to the draggable (specify a pixel value from the top, right, bottom, and/or left).</p>
|
|
</div><!-- End demo-description -->
|
|
|
|
</body>
|
|
</html>
|