49 lines
1.2 KiB
HTML
49 lines
1.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Shapes - Collision</title>
|
|
<style>
|
|
* {
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
html {
|
|
height: 100%;
|
|
}
|
|
|
|
body {
|
|
min-height: 100%;
|
|
position: relative;
|
|
margin: 0;
|
|
}
|
|
|
|
folk-shape {
|
|
border: 2px solid black;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<folk-shape x="100" y="100" width="50" height="50"> Hello World </folk-shape>
|
|
<folk-shape x="200" y="200" width="50" height="50"></folk-shape>
|
|
|
|
<script type="module">
|
|
import '../src/standalone/folk-shape.ts';
|
|
import { collisionDetection } from '../src/common/collision.ts';
|
|
|
|
const geometryElements = document.querySelectorAll('folk-shape');
|
|
|
|
function handleCollision(e) {
|
|
geometryElements.forEach((el) => {
|
|
if (el !== e.target && collisionDetection(el.getClientRect(), e.target.getClientRect())) {
|
|
e.preventDefault();
|
|
}
|
|
});
|
|
}
|
|
|
|
document.addEventListener('transform', handleCollision);
|
|
</script>
|
|
</body>
|
|
</html>
|