家具模拟摆放源码怎么用
```html
body {
fontfamily: Arial, sansserif;
}
floorplan {
width: 600px;
height: 400px;
border: 2px solid 333;
position: relative;
}
.furniture {
position: absolute;
border: 1px solid 666;
padding: 10px;
backgroundcolor: f2f2f2;
cursor: move;
}
家具模拟摆放
将家具拖动到平面图中进行摆放。
let activeItem = null;
document.querySelectorAll('.furniture').forEach(item => {
item.addEventListener('mousedown', (e) => {
activeItem = item;
});
});
document.getElementById('floorplan').addEventListener('mousemove', (e) => {
if (activeItem) {
activeItem.style.left = e.pageX 10 'px';
activeItem.style.top = e.pageY 10 'px';
}
});
document.getElementById('floorplan').addEventListener('mouseup', () => {
activeItem = null;
});