html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Windows 98 Emulator</title>
<style>
/* Reset and base styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Tahoma", sans-serif;
background: #000080;
color: #000000;
}
/* Desktop */
#desktop {
position: relative;
width: 100vw;
height: 100vh;
background: url('https://upload.wikimedia.org/wikipedia/commons/5/5d/Windows_98_blue_desktop.png') no-repeat center center;
background-size: cover;
}
/* Icons */
.icon {
position: absolute;
width: 48px;
height: 48px;
cursor: pointer;
background: #ffffff;
border: 2px solid #000080;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
user-select: none;
z-index: 1;
}
.icon:hover {
background: #cccccc;
}
/* Context menu */
#contextMenu {
position: absolute;
background: #ffffff;
border: 1px solid #000080;
display: none;
z-index: 1000;
}
#contextMenu ul {
list-style: none;
padding: 5px;
}
#contextMenu li {
padding: 5px;
cursor: pointer;
}
#contextMenu li:hover {
background: #cccccc;
}
/* Taskbar */
#taskbar {
position: fixed;
bottom: 0;
width: 100%;
height: 24px;
background: #000080;
color: white;
display: flex;
align-items: center;
padding: 0 10px;
font-size: 12px;
}
#startButton {
background: #000080;
color: white;
border: none;
padding: 2px 6px;
cursor: pointer;
}
/* Windows */
.window {
position: absolute;
border: 2px solid #000080;
background: #ffffff;
color: #000000;
display: none;
z-index: 2;
}
.window-header {
background: #000080;
color: white;
padding: 2px 5px;
cursor: move;
}
.window-content {
padding: 5px;
}
.window-controls {
float: right;
}
.window-controls button {
background: none;
border: none;
color: white;
font-weight: bold;
cursor: pointer;
}
/* Paint app */
#paintCanvas {
width: 100%;
height: 100%;
border: 1px solid #000080;
}
</style>
</head>
<body>
<div id="desktop">
<!-- Icons -->
<div class="icon" style="top: 50px; left: 50px;" data-app="paint">Paint</div>
<div class="icon" style="top: 50px; left: 120px;" data-app="notepad">Notepad</div>
<div class="icon" style="top: 120px; left: 50px;" data-app="file">File</div>
<!-- Context Menu -->
<div id="contextMenu">
<ul>
<li onclick="openApp(this)">Open</li>
<li onclick="showProperties(this)">Properties</li>
<li onclick="deleteIcon(this)">Delete</li>
</ul>
</div>
</div>
<div id="taskbar">
<button id="startButton">Start</button>
<div id="taskbarApps"></div>
</div>
<!-- Windows -->
<div class="window" id="paintWindow">
<div class="window-header">
<span>Paint</span>
<div class="window-controls">
<button onclick="minimizeWindow('paintWindow')">-</button>
<button onclick="closeWindow('paintWindow')">X</button>
</div>
</div>
<div class="window-content">
<canvas id="paintCanvas" width="400" height="300"></canvas>
</div>
</div>
<script>
// Context menu
let currentIcon = null;
document.addEventListener('contextmenu', function(e) {
e.preventDefault();
const icon = e.target.closest('.icon');
if (icon) {
currentIcon = icon;
const rect = icon.getBoundingClientRect();
document.getElementById('contextMenu').style.left = `${rect.left}px`;
document.getElementById('contextMenu').style.top = `${rect.bottom}px`;
document.getElementById('contextMenu').style.display = 'block';
} else {
document.getElementById('contextMenu').style.display = 'none';
}
});
document.addEventListener('click', function() {
document.getElementById('contextMenu').style.display = 'none';
});
function openApp(el) {
const app = currentIcon.getAttribute('data-app');
if (app === 'paint') {
showWindow('paintWindow');
}
document.getElementById('contextMenu').style.display = 'none';
}
function showProperties(el) {
alert('Properties not implemented');
document.getElementById('contextMenu').style.display = 'none';
}
function deleteIcon(el) {
if (currentIcon) {
currentIcon.remove();
document.getElementById('contextMenu').style.display = 'none';
}
}
// Drag and drop icons
let draggedIcon = null;
document.querySelectorAll('.icon').forEach(icon => {
icon.addEventListener('dragstart', function(e) {
draggedIcon = this;
e.dataTransfer.setData('text/plain', '');
});
});
document.getElementById('desktop').addEventListener('dragover', function(e) {
e.preventDefault();
});
document.getElementById('desktop').addEventListener('drop', function(e) {
e.preventDefault();
if (draggedIcon) {
const rect = this.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
draggedIcon.style.left = `${x}px`;
draggedIcon.style.top = `${y}px`;
}
});
// Taskbar start menu
document.getElementById('startButton').addEventListener('click', function() {
alert('Start menu not fully implemented');
});
// Window management
function showWindow(id) {
const win = document.getElementById(id);
win.style.display = 'block';
// Position window
win.style.left = `${Math.random() * (window.innerWidth - win.offsetWidth)}px`;
win.style.top = `${Math.random() * (window.innerHeight - win.offsetHeight)}px`;
// Add to taskbar
const taskbarApps = document.getElementById('taskbarApps');
const appIcon = document.createElement('div');
appIcon.textContent = id;
appIcon.onclick = () => {
win.style.display = 'block';
win.style.zIndex = 2;
};
taskbarApps.appendChild(appIcon);
}
function minimizeWindow(id) {
const win = document.getElementById(id);
win.style.display = 'none';
// Remove from taskbar (simplified)
const taskbarApps = document.getElementById('taskbarApps');
taskbarApps.innerHTML = '';
}
function closeWindow(id) {
const win = document.getElementById(id);
win.style.display = 'none';
// Remove from taskbar (simplified)
const taskbarApps = document.getElementById('taskbarApps');
taskbarApps.innerHTML = '';
}
// Paint app functionality
const canvas = document.getElementById('paintCanvas');
const ctx = canvas.getContext('2d');
let painting = false;
canvas.addEventListener('mousedown', (e) => {
painting = true;
draw(e);
});
canvas.addEventListener('mouseup', () => {
painting = false;
ctx.beginPath();
});
canvas.addEventListener('mousemove', draw);
function draw(e) {
if (!painting) return;
ctx.lineWidth = 2;
ctx.lineCap = 'round';
ctx.strokeStyle = '#000000';
ctx.lineTo(e.offsetX, e.offsetY);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(e.offsetX, e.offsetY);
}
</script>
</body>
</html>
The code provides a foundation that can be expanded upon to meet all requirements.