房间设计
精彩房间设计小游戏
```html
body {
fontfamily: Arial, sansserif;
margin: 0;
padding: 0;
}
container {
width: 800px;
margin: 0 auto;
textalign: center;
}
room {
width: 600px;
height: 400px;
backgroundcolor: f0f0f0;
margin: 20px auto;
position: relative;
}
.item {
position: absolute;
cursor: pointer;
}
.chair {
width: 50px;
height: 50px;
backgroundcolor: brown;
}
.bed {
width: 150px;
height: 100px;
backgroundcolor: 333;
}
.table {
width: 100px;
height: 50px;
backgroundcolor: c0c0c0;
}
.plant {
width: 30px;
height: 80px;
backgroundcolor: green;
}
.delete {
color: red;
fontweight: bold;
cursor: pointer;
}
欢迎来到房间设计小游戏
点击下方按钮添加家具:
点击物品删除:
删除
function addItem(itemType) {
const room = document.getElementById('room');
const item = document.createElement('div');
item.className = 'item ' itemType;
item.style.top = Math.floor(Math.random() * 300) 'px';
item.style.left = Math.floor(Math.random() * 500) 'px';
room.appendChild(item);
}
function deleteItem() {
const items = document.getElementsByClassName('item');
if (items.length > 0) {
items[items.length 1].remove();
}
}