float windows multiple

by Andy Bulka

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Dynamic Floating Windows</title>
  <style>
    body {
      font-family: Arial, sans-serif;
    }
    .floating-window {
      position: absolute;
      top: 100px;
      left: 100px;
      width: 300px;
      height: 200px;
      background: white;
      border: 1px solid black;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
      resize: both;
      overflow: hidden;
    }
    .window-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 5px;
      background: #ddd;
      cursor: move;
    }
    .window-content {
      height: calc(100% - 30px); /* Adjust for header height */
      padding: 0;
      margin: 0;
    }
    .window-content textarea {
      width: 100%;
      height: 100%;
      border: none;
      padding: 0;
      margin: 0;
      resize: none;
      outline: none;
    }
    #create-window-btn {
      margin: 10px;
      padding: 10px 20px;
      font-size: 16px;
      cursor: pointer;
      background: #007bff;
      color: white;
      border: none;
      border-radius: 4px;
    }
    #create-window-btn:hover {
      background: #0056b3;
    }
  </style>
</head>
<body>
  <button id="create-window-btn">Create New Window</button>

  <script>
    let windowCount = 0;
    let zIndexCounter = 1;

    function setupFloatingWindow(windowEl) {
      const header = windowEl.querySelector('.window-header');
      const closeBtn = windowEl.querySelector('.close-btn');

      // Bring the window to the top when clicked
      windowEl.addEventListener('mousedown', () => {
        zIndexCounter++;
        windowEl.style.zIndex = zIndexCounter;
      });

      closeBtn.addEventListener('click', () => {
        windowEl.remove();
      });

      let isDragging = false;
      let offsetX, offsetY;

      header.addEventListener('mousedown', (e) => {
       ...