jQuery Draggable Input Elements
I am trying to make form elements draggable using jQ开发者_如何学Pythonuery UI. For example, buttons, checkboxes, textfields, etc. So far I have had no luck. Do you have any ideas how to accomplish this?
Maybe 3 years too late but you could dispatch event and use following snippet for a more expected behaviour:
DEMO jsFiddle
$(".draggable").draggable({
start: function (event, ui) {
$(this).data('preventBehaviour', true);
}
});
$(".draggable").find(":input").on('mousedown', function (e) {
var mdown = new MouseEvent("mousedown", {
screenX: e.screenX,
screenY: e.screenY,
clientX: e.clientX,
clientY: e.clientY,
view: window
});
$(this).closest('.draggable')[0].dispatchEvent(mdown);
}).on('click', function (e) {
var $draggable = $(this).closest('.draggable');
if ($draggable.data("preventBehaviour")) {
e.preventDefault();
$draggable.data("preventBehaviour", false)
}
});
The trick consists to put a transparent div over the inputs elements :
div div{
position:absolute;
z-index:2;
height: 100%;
width: 100%;
}
div input{
position:relative;
z-index:1;
}
<div><div> </div><input type="text" value="..." disabled="true"/></div>
$('body>div').draggable();
I think this best suits your requirements :) Its draggable + resizable on input element, yet you don't lose their nature to be editable.
$(function(){
$('.draggable').draggable().resizable();
});
Here's my solution for you: my jsFiddle.
Well input elements need to be editable, so making them draggable would make them uneditable.
Wrap them in a <span>
or a <div>
, and I strongly suggest you use a handle.
Another option is to put it in wrapper and set this CSS for the input:
pointer-events: none;
You wan't be able to enter modify the input values.
the best solution is that you put them into a div or span
精彩评论