ISSUE: Can not give input on the input fields
// Make the DIV element draggable:
dragElement(document.getElementById("mydiv"));
function dragElement(elmnt) {
var pos1 = 0,
pos2 = 0,
pos3 = 0,
pos4 = 0;
if (document.getElementById(elmnt.id "header")) {
// if present, the header is where you move the DIV from:
document.getElementById(elmnt.id "header").onmousedown = dragMouseDown;
} else {
// otherwise, move the DIV from anywhere inside the DIV:
elmnt.onmousedown = dragMouseDown;
}
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
elmnt.style.top = (elmnt.offsetTop - pos2) "px";
elmnt.style.left = (elmnt.offsetLeft - pos1) "px";
}
function closeDragElement() {
// stop moving when mouse button is released:
document.onmouseup = null;
document.onmousemove = null;
}
}
#mydiv {
width: 50%;
position: absolute;
}
#mydivheader {
padding: 1px;
cursor: move;
z-index: 10;
color: rgb(211, 211, 211);
}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg OMhuP IlRH9sENBO0LRn5q 8nbTov4 1p" crossorigin="anonymous"></script>
<!-- Draggable DIV -->
<div id="mydiv" >
<!-- Include a header DIV with the same name as the draggable DIV, followed by "header" -->
<div id="mydivheader" >
<div >
<div >
<div >
<div >
<div >
<input type="text" placeholder="Titel toevoegen">
</div>
</div>
<br>
<div >
<div >
<input type="date" id="date_start" >
</div>
<div >
<input type="time" id="time_start" >
</div>
<div >
<input type="time" id="time_end" >
</div>
</div>
<br>
<div >
<div >
<textarea rows="6" placeholder="Beschrijving...."></textarea>
</div>
</div>
<br>
<div >
<div >
<input type="submit" value="opslaan">
</div>
</div>
</div>
<div >
<button id="hide_card" onclick="hide(event)" >X</button>
</div>
</div>
</div>
</div>
</div>
CodePudding user response:
use HTML5 Drag Event to do the Drag & Drop functionality. Here you have disabled the mouse interaction by using event.preventDefault
.If you remove event.preventDefault
then you will able type in there. Using above script you can move & type in the form using tab.