下面是一个使用 Matter.js 创建的示例,包含一个地面、由4个长方形组成的封闭箱体,箱体内有10个不同颜色的小球。箱体可以被拖动,而小球被限制在箱体内部。
<!DOCTYPE html>
<html>
<head>
<title>Matter.js 可拖动箱体与小球</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background: #f0f0f0;
}
canvas {
display: block;
}
#info {
position: absolute;
top: 10px;
left: 10px;
background: rgba(255, 255, 255, 0.7);
padding: 10px;
border-radius: 5px;
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<div id="info">拖动箱体移动