mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Draggable demo: Implemented cursorAt option in cursor-style demo.
This commit is contained in:
parent
a87c1dc068
commit
f5ceca740f
@ -7,16 +7,41 @@
|
||||
<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.mouse.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: { cursor: "move", top: 56, left: 56 } });
|
||||
$( "#draggable2" ).draggable({ cursorAt: { cursor: "crosshair", top: -5, left: -5 } });
|
||||
$( "#draggable" ).draggable({ cursorAt: { top: 56, left: 56 } });
|
||||
$( "#draggable2" ).draggable({ cursorAt: { top: -5, left: -5 } });
|
||||
$( "#draggable3" ).draggable({ cursorAt: { bottom: 0 } });
|
||||
});
|
||||
</script>
|
||||
@ -24,9 +49,9 @@
|
||||
<body>
|
||||
|
||||
<div class="demo">
|
||||
|
||||
|
||||
<div id="draggable" class="ui-widget-content">
|
||||
<p>I will always stick to the center (relative to the mouse)</p>
|
||||
<p>I will always stick to the center (relative to the pointer)</p>
|
||||
</div>
|
||||
|
||||
<div id="draggable2" class="ui-widget-content">
|
||||
@ -42,7 +67,7 @@
|
||||
|
||||
|
||||
<div class="demo-description">
|
||||
<p>Position the cursor while dragging the object. By default the cursor appears in the center of the dragged object; 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). Customize the cursor's appearance by supplying the <code>cursor</code> option with a valid CSS cursor value: default, move, pointer, crosshair, etc.</p>
|
||||
<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>
|
||||
|
Loading…
Reference in New Issue
Block a user