Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
FunnyDoggs authored Feb 26, 2024
1 parent 62960ed commit 8a391fc
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
</div>

<script>
// Existing script...
// Function to make the window draggable
dragElement(document.getElementById("window"));

// Function to initialize resizing
function initResize(e) {
Expand Down Expand Up @@ -99,6 +100,52 @@
document.removeEventListener('mousemove', handleMouseMove);
document.removeEventListener('mouseup', stopResize);
}

function dragElement(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if (document.getElementById(elmnt.id + "-title-bar")) {
// if present, the header is where you move the DIV from:
document.getElementById(elmnt.id + "-title-bar").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 the mouse button is released:
document.onmouseup = null;
document.onmousemove = null;
}
}

// Function to close the window
function closeWindow() {
document.getElementById("window").style.display = "none";
}
</script>
</body>
</html>

0 comments on commit 8a391fc

Please sign in to comment.