I'm trying to have a draggable div which can also be dragged from a textarea within it.
html:
<div id="divContainer">
<textarea id="text"></textarea>
</div>
css:
#divContainer {
position: absolute;
left: 10px;
top: 10px;
width: 100px;
height: 100px;
background-color: blue;
}
#text {
position: absolute;
left: 5px;
top: 5px;
width: 50px;
height: 50px;
background-color: green;
}
jquery:
$("#divContainer").draggable();
I can drag the div
if I drag by clicking in the div
area, but not if I click into the textarea
area.
Is there a way to solve this ?
Here is the jsFiddle
To make an object draggable set draggable=true on that element. Just about anything can be drag-enabled: images, files, links, files, or any markup on your page. Our example creates an interface to rearrange columns that have been laid out with CSS Grid.
All you need to do is define draggable=true in your element and code the relevant ondragstart and ondragend logic. This works with both vanilla JS and frameworks like React.
Check Out this fiddle perfect for you
FIDDLE
Code:
HTML:
<div>
<textarea name="ta" id="ta" cols="30" rows="10"></textarea>
</div>
CSS:
div {
background-color:#aaa;
padding: 4px;
text-align: center;
position:relative;
}
JS:
$('div').draggable({
cancel: "ta",
start: function (){
$('#ta').focus();
} ,
stop: function (){
$('#ta').focus();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With