Make a popup box resizable and draggable?

OK, I followed the comprehensive instructions in the Xway manual to create a popup box (p.95) and have it working. Excellent!

I now want to make the popup box resizable and draggable.

Let’s do resizable first. AI tells me to make it resizable I need to add resize: both; overflow: auto; to the .overlay class (I called the box ‘overlay’ as per the Xway instructions).

If I add those in Xway as “Extended HTML Attributes” to the overlay box, that appears in the HTML as <div id="overlay" resize="both"> which obviously does nothing.

If I add these properties to “Extended Properties” in Xway, it appears in the #overlay ID in <style> in <head>. This also does not make the box resizable:

#overlay { display:none; visibility:visible; position:fixed; left:0; top:0; right:0; bottom:0; min-height:100px; z-index:3; background:rgba(48,88,176,0.5); color:rgb(102,102,102); font-family:Helvetica,Arial,sans-serif; font-size:small; resize:both }

Looking at the HTML source, I cannot see a .overlay class anywhere… so any clues as to how I achieve a resizable box?

Thanks!

Hi BJ,

  1. You want to target the “popup” box rather than the “overlay” box. The overlay box has Fixed position and is set to cover the content area of the window to provide a transparent dark background.
  2. resize is a CSS property rather than an HTML attribute, so you need to add it in the Extended Properties section of the Box Inspector.
  3. You don’t need to set a class unless you are applying a property to multiple elements. If you apply a property to a box, Xway uses the box ID to target that particular box. (Xway uses classes when outputting text styles.)
  4. You don’t need to use an extended property to set overflow: you can choose Auto from the Overflow popup in the Style section of the Box Inspector.

So the only changes you need to make after following the steps in the Xway User Guide are:

  1. Select the “popup” box.
  2. Add resize (name) both (property) in the Extended Properties section of the Box Inspector.
  3. Choose Auto from the Overflow popup in the Style section of the Box Inspector.

If you do this, you should see that the popup box has a resize widget in the bottom right corner.

1 Like

Fantastic thankyou - that works!

Dare I ask how the best way to make the popup draggable? AI says this JS needs to be added:

const popup = document.getElementById("popup");
const header = document.getElementById("popupHeader");
const resizeHandle = document.getElementById("resizeHandle");

let x = 0, y = 0, w = 0, h = 0;

// --- Dragging Logic ---
header.addEventListener("mousedown", (e) => {
e.preventDefault();
// Get initial mouse position
x = e.clientX;
y = e.clientY;

document.addEventListener("mousemove", dragMove);
document.addEventListener("mouseup", dragStop);
});

function dragMove(e) {
// Calculate how far the mouse moved
const dx = e.clientX - x;
const dy = e.clientY - y;

// Update popup coordinates
popup.style.left = ${popup.offsetLeft + dx}px;
popup.style.top = ${popup.offsetTop + dy}px;

// Reset initial mouse markers
x = e.clientX;
y = e.clientY;
}

function dragStop() {
document.removeEventListener("mousemove", dragMove);
document.removeEventListener("mouseup", dragStop);
}

// --- Resizing Logic ---
resizeHandle.addEventListener("mousedown", (e) => {
e.preventDefault();
// Get initial size and mouse position
w = popup.clientWidth;
h = popup.clientHeight;
x = e.clientX;
y = e.clientY;

document.addEventListener("mousemove", resizeMove);
document.addEventListener("mouseup", resizeStop);
});

function resizeMove(e) {
// Calculate new width and height
const dw = e.clientX - x;
const dh = e.clientY - y;

popup.style.width = ${w + dw}px;
popup.style.height = ${h + dh}px;
}

function resizeStop() {
document.removeEventListener("mousemove", resizeMove);
document.removeEventListener("mouseup", resizeStop);
}

I’m not expecting you critique the JS, but:

  1. is this the only way to make the box draggable, or do you have any other suggestions?
  2. Should the JS be added to the overlay box, or to the popup box?

And since the CSS is now making the box resizable, I assume I can delete the resizing bits in the JS, and have it only do the dragging bits.

Thanks & cheers

I don’t think it’s possible (in a non-hacky way) to create a draggable box using CSS, so you probably do need to use JavaScript.

There are some good sites that have non-AI information about HTML and CSS. These are being plagiarised by AI, sadly, but they’re often more user-friendly. Here is one page that might be a good starting point: How to Create a Draggable HTML Element.

Answering your second question: you want to target the “popup” box (as before), and you don’t need to use JavaScript for resizing. If you follow the W3Schools page mentioned above, one thing you will need to do is set the box to have absolute position instead of relative position (choose Absolute from the Position popup in the Style section of the Box Inspector).

The W3Schools example also assumes that you have a “header” box within the popup box. This provides an area that users can drag (like a window bar on macOS).

The simplest way to add JavaScript on an Xway page is to put it in the JavaScript Markup section of the Page Inspector.

1 Like

There is also a draggable HTML attribute, which is very simple: you can set this by adding draggable (name) true (value) in the Extended HTML Attributes section of the Box Inspector.

… but when I tried it in Safari, it created a temporary draggable copy of the popup, so I don’t think it’s what you’re looking for.

(I think it’s actually intended to be used for drag and drop operations.)

1 Like