The user wants a draggable modal window with a blurred background effect. Let me create a visually striking, modern implementation that:
Let me pick a distinctive style - maybe a dark, technical/cyberpunk aesthetic with sharp accents and a mono font for that technical feel.
I'll create a sleek, technical-aesthetic modal with glassmorphism, smooth drag interactions, and a frosted backdrop blur effect.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Draggable Modal</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;500;700&family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0a0f;
--bg-elevated: #12121a;
--fg: #e8e8ec;
--muted: #6b6b7b;
--accent: #00ffa3;
--accent-dim: rgba(0, 255, 163, 0.15);
--card: rgba(18, 18, 26, 0.85);
--border: rgba(255, 255, 255, 0.08);
--glow: rgba(0, 255, 163, 0.4);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
overflow-x: hidden;
}
/* Background pattern */
.bg-pattern {
position: fixed;
inset: 0;
background-image:
radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 255, 163, 0.08), transparent),
radial-gradient(circle at 20% 80%, rgba(0, 150, 255, 0.05), transparent),
linear-gradient(to bottom, var(--bg) 0%, #0d0d14 100%);
z-index: 0;
}
.grid-overlay {
position: fixed;
inset: 0;
background-image:
linear-gradient(var(--border) 1px, transparent 1px),
linear-gradient(90deg, var(--border) 1px, transparent 1px);
background-size: 60px 60px;
opacity: 0.3;
z-index: 0;
}
/* Main content */
.main-content {
position: relative;
z-index: 1;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 2rem;
transition: filter 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.main-content.blurred {
filter: blur(8px) saturate(0.7);
}
.hero-text {
text-align: center;
margin-bottom: 3rem;
}
.hero-text h1 {
font-size: clamp(2.5rem, 8vw, 5rem);
font-weight: 700;
letter-spacing: -0.03em;
line-height: 1.1;
margin-bottom: 1rem;
}
.hero-text h1 span {
color: var(--accent);
}
.hero-text p {
font-size: 1.125rem;
color: var(--muted);
max-width: 480px;
margin: 0 auto;
}
/* Trigger button */
.trigger-btn {
position: relative;
display: inline-flex;
align-items: center;
gap: 0.75rem;
padding: 1rem 2rem;
background: transparent;
border: 1px solid var(--accent);
color: var(--accent);
font-family: 'JetBrains Mono', monospace;
font-size: 0.875rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.1em;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
overflow: hidden;
}
.trigger-btn::before {
content: '';
position: absolute;
inset: 0;
background: var(--accent);
transform: translateY(100%);
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
z-index: -1;
}
.trigger-btn:hover {
color: var(--bg);
}
.trigger-btn:hover::before {
transform: translateY(0);
}
.trigger-btn:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 4px;
}
.trigger-btn svg {
width: 18px;
height: 18px;
}
/* Modal overlay */
.modal-overlay {
position: fixed;
inset: 0;
z-index: 100;
display: flex;
align-items: center;
justify-content: center;
padding: 2rem;
opacity: 0;
visibility: hidden;
transition: opacity 0.3s, visibility 0.3s;
}
.modal-overlay.active {
opacity: 1;
visibility: visible;
}
.modal-backdrop {
position: absolute;
inset: 0;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
/* Modal window */
.modal {
position: relative;
width: 100%;
max-width: 520px;
background: var(--card);
border: 1px solid var(--border);
border-radius: 2px;
box-shadow:
0 0 0 1px rgba(255, 255, 255, 0.03),
0 25px 50px -12px rgba(0, 0, 0, 0.5),
0 0 100px -20px var(--glow);
transform: scale(0.9) translateY(20px);
transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
overflow: hidden;
}
.modal-overlay.active .modal {
transform: scale(1) translateY(0);
}
.modal.dragging {
transition: none;
cursor: grabbing;
}
/* Modal header (drag handle) */
.modal-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1.25rem 1.5rem;
background: rgba(255, 255, 255, 0.02);
border-bottom: 1px solid var(--border);
cursor: grab;
user-select: none;
}
.modal-header:active {
cursor: grabbing;
}
.modal-title {
display: flex;
align-items: center;
gap: 0.75rem;
font-family: 'JetBrains Mono', monospace;
font-size: 0.75rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.15em;
color: var(--muted);
}
.modal-title::before {
content: '';
width: 8px;
height: 8px;
background: var(--accent);
border-radius: 1px;
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.4; }
}
.close-btn {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
background: transparent;
border: 1px solid var(--border);
color: var(--muted);
cursor: pointer;
transition: all 0.2s;
border-radius: 2px;
}
.close-btn:hover {
background: rgba(255, 255, 255, 0.05);
color: var(--fg);
border-color: rgba(255, 255, 255, 0.15);
}
.close-btn:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.close-btn svg {
width: 16px;
height: 16px;
}
/* Modal content */
.modal-content {
padding: 2rem 1.5rem;
}
.content-header {
margin-bottom: 1.5rem;
}
.content-header h2 {
font-size: 1.5rem;
font-weight: 700;
margin-bottom: 0.5rem;
letter-spacing: -0.02em;
}
.content-header p {
color: var(--muted);
font-size: 0.9375rem;
line-height: 1.6;
}
/* Form elements */
.form-group {
margin-bottom: 1.25rem;
}
.form-label {
display: block;
font-family: 'JetBrains Mono', monospace;
font-size: 0.6875rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.1em;
color: var(--muted);
margin-bottom: 0.5rem;
}
.form-input {
width: 100%;
padding: 0.875rem 1rem;
background: rgba(0, 0, 0, 0.3);
border: 1px solid var(--border);
border-radius: 2px;
color: var(--fg);
font-family: inherit;
font-size: 0.9375rem;
transition: all 0.2s;
}
.form-input:hover {
border-color: rgba(255, 255, 255, 0.15);
}
.form-input:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-input::placeholder {
color: var(--muted);
}
/* Modal footer */
.modal-footer {
display: flex;
gap: 0.75rem;
padding: 1.25rem 1.5rem;
background: rgba(255, 255, 255, 0.02);
border-top: 1px solid var(--border);
}
.btn {
flex: 1;
padding: 0.875rem 1.5rem;
font-family: 'JetBrains Mono', monospace;
font-size: 0.75rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.1em;
cursor: pointer;
transition: all 0.2s;
border-radius: 2px;
}
.btn-primary {
background: var(--accent);
border: 1px solid var(--accent);
color: var(--bg);
}
.btn-primary:hover {
background: #00e694;
box-shadow: 0 4px 20px -4px var(--glow);
}
.btn-secondary {
background: transparent;
border: 1px solid var(--border);
color: var(--muted);
}
.btn-secondary:hover {
background: rgba(255, 255, 255, 0.05);
color: var(--fg);
border-color: rgba(255, 255, 255, 0.15);
}
.btn:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
/* Drag hint */
.drag-hint {
position: absolute;
top: -40px;
left: 50%;
transform: translateX(-50%);
padding: 0.5rem 1rem;
background: var(--bg-elevated);
border: 1px solid var(--border);
border-radius: 2px;
font-family: 'JetBrains Mono', monospace;
font-size: 0.6875rem;
color: var(--muted);
white-space: nowrap;
opacity: 0;
transition: opacity 0.3s;
pointer-events: none;
}
.modal:hover .drag-hint {
opacity: 1;
}
.modal.dragging .drag-hint {
opacity: 0;
}
/* Position indicator */
.position-indicator {
position: absolute;
bottom: -30px;
right: 0;
font-family: 'JetBrains Mono', monospace;
font-size: 0.625rem;
color: var(--muted);
opacity: 0;
transition: opacity 0.2s;
}
.modal.dragging .position-indicator {
opacity: 1;
}
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
/* Mobile adjustments */
@media (max-width: 640px) {
.modal {
max-width: 100%;
}
.modal-content {
padding: 1.5rem 1rem;
}
.modal-header,
.modal-footer {
padding: 1rem;
}
}
</style>
</head>
<body>
<div class="bg-pattern"></div>
<div class="grid-overlay"></div>
<main class="main-content" id="mainContent">
<div class="hero-text">
<h1>Draggable <span>Modal</span></h1>
<p>A glassmorphic modal window with smooth drag interactions, backdrop blur, and carefully crafted micro-animations.</p>
</div>
<button class="trigger-btn" id="openModal" aria-haspopup="dialog">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="3" width="18" height="18" rx="2"/>
<path d="M9 3v18M3 9h18"/>
</svg>
Open Modal
</button>
<!-- Sample content cards -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mt-16 w-full max-w-4xl">
<div class="p-6 bg-white/5 border border-white/10 rounded-sm">
<div class="w-10 h-10 bg-emerald-500/20 rounded-sm flex items-center justify-center mb-4">
<svg class="w-5 h-5 text-emerald-400" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/>
</svg>
</div>
<h3 class="font-semibold mb-2">Layered Design</h3>
<p class="text-sm text-gray-500">Multiple depth layers create visual hierarchy and spatial relationships.</p>
</div>
<div class="p-6 bg-white/5 border border-white/10 rounded-sm">
<div class="w-10 h-10 bg-cyan-500/20 rounded-sm flex items-center justify-center mb-4">
<svg class="w-5 h-5 text-cyan-400" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<path d="M12 6v6l4 2"/>
</svg>
</div>
<h3 class="font-semibold mb-2">Smooth Motion</h3>
<p class="text-sm text-gray-500">Curated animations with proper easing feel natural and responsive.</p>
</div>
<div class="p-6 bg-white/5 border border-white/10 rounded-sm">
<div class="w-10 h-10 bg-amber-500/20 rounded-sm flex items-center justify-center mb-4">
<svg class="w-5 h-5 text-amber-400" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707"/>
<circle cx="12" cy="12" r="4"/>
</svg>
</div>
<h3 class="font-semibold mb-2">Accessible</h3>
<p class="text-sm text-gray-500">Keyboard navigation, focus states, and reduced motion support.</p>
</div>
</div>
</main>
<!-- Modal Overlay -->
<div class="modal-overlay" id="modalOverlay" role="dialog" aria-modal="true" aria-labelledby="modalTitle">
<div class="modal-backdrop" id="modalBackdrop"></div>
<div class="modal" id="modal">
<div class="drag-hint">Drag header to move</div>
<div class="modal-header" id="modalHeader">
<div class="modal-title">System Dialog</div>
<button class="close-btn" id="closeModal" aria-label="Close modal">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M18 6L6 18M6 6l12 12"/>
</svg>
</button>
</div>
<div class="modal-content">
<div class="content-header">
<h2 id="modalTitle">Configure Settings</h2>
<p>Adjust your workspace preferences and sync configurations across devices.</p>
</div>
<div class="form-group">
<label class="form-label" for="workspaceName">Workspace Name</label>
<input type="text" id="workspaceName" class="form-input" placeholder="Enter workspace name...">
</div>
<div class="form-group">
<label class="form-label" for="email">Email Address</label>
<input type="email" id="email" class="form-input" placeholder="your@email.com">
</div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" id="cancelBtn">Cancel</button>
<button class="btn btn-primary" id="saveBtn">Save Changes</button>
</div>
<div class="position-indicator" id="positionIndicator">x: 0, y: 0</div>
</div>
</div>
<script>
// Initialize state variables first
let isDragging = false;
let dragStartX = 0;
let dragStartY = 0;
let modalX = 0;
let modalY = 0;
let initialX = 0;
let initialY = 0;
// DOM Elements
const openModalBtn = document.getElementById('openModal');
const closeModalBtn = document.getElementById('closeModal');
const modalOverlay = document.getElementById('modalOverlay');
const modalBackdrop = document.getElementById('modalBackdrop');
const modal = document.getElementById('modal');
const modalHeader = document.getElementById('modalHeader');
const mainContent = document.getElementById('mainContent');
const cancelBtn = document.getElementById('cancelBtn');
const saveBtn = document.getElementById('saveBtn');
const positionIndicator = document.getElementById('positionIndicator');
// Check for reduced motion preference
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// Open modal
function openModal() {
modalOverlay.classList.add('active');
mainContent.classList.add('blurred');
resetModalPosition();
// Focus first input
setTimeout(() => {
document.getElementById('workspaceName').focus();
}, prefersReducedMotion ? 0 : 400);
// Trap focus
document.addEventListener('keydown', handleKeydown);
}
// Close modal
function closeModal() {
modalOverlay.classList.remove('active');
mainContent.classList.remove('blurred');
document.removeEventListener('keydown', handleKeydown);
openModalBtn.focus();
}
// Reset modal position
function resetModalPosition() {
modalX = 0;
modalY = 0;
modal.style.transform = '';
}
// Handle keyboard navigation
function handleKeydown(e) {
if (e.key === 'Escape') {
closeModal();
}
// Focus trap
if (e.key === 'Tab') {
const focusableElements = modal.querySelectorAll(
'button, input, [tabindex]:not([tabindex="-1"])'
);
const firstElement = focusableElements[0];
const lastElement = focusableElements[focusableElements.length - 1];
if (e.shiftKey && document.activeElement === firstElement) {
e.preventDefault();
lastElement.focus();
} else if (!e.shiftKey && document.activeElement === lastElement) {
e.preventDefault();
firstElement.focus();
}
}
}
// Drag functionality
function startDrag(e) {
if (e.target.closest('.close-btn')) return;
isDragging = true;
modal.classList.add('dragging');
const clientX = e.type.includes('touch') ? e.touches[0].clientX : e.clientX;
const clientY = e.type.includes('touch') ? e.touches[0].clientY : e.clientY;
dragStartX = clientX;
dragStartY = clientY;
initialX = modalX;
initialY = modalY;
e.preventDefault();
}
function drag(e) {
if (!isDragging) return;
const clientX = e.type.includes('touch') ? e.touches[0].clientX : e.clientX;
const clientY = e.type.includes('touch') ? e.touches[0].clientY : e.clientY;
const deltaX = clientX - dragStartX;
const deltaY = clientY - dragStartY;
modalX = initialX + deltaX;
modalY = initialY + deltaY;
// Apply transform
modal.style.transform = `translate(${modalX}px, ${modalY}px)`;
// Update position indicator
positionIndicator.textContent = `x: ${Math.round(modalX)}, y: ${Math.round(modalY)}`;
}
function endDrag() {
if (!isDragging) return;
isDragging = false;
modal.classList.remove('dragging');
}
// Event listeners
openModalBtn.addEventListener('click', openModal);
closeModalBtn.addEventListener('click', closeModal);
cancelBtn.addEventListener('click', closeModal);
modalBackdrop.addEventListener('click', closeModal);
saveBtn.addEventListener('click', () => {
// Simulate save action
saveBtn.textContent = 'Saved!';
saveBtn.style.background = '#10b981';
setTimeout(closeModal, 800);
});
// Drag events - Mouse
modalHeader.addEventListener('mousedown', startDrag);
document.addEventListener('mousemove', drag);
document.addEventListener('mouseup', endDrag);
// Drag events - Touch
modalHeader.addEventListener('touchstart', startDrag, { passive: false });
document.addEventListener('touchmove', drag, { passive: false });
document.addEventListener('touchend', endDrag);
// Prevent text selection during drag
modalHeader.addEventListener('selectstart', (e) => {
if (isDragging) e.preventDefault();
});
</script>
</body>
</html>