update demo
This commit is contained in:
parent
e2234b8021
commit
01397c52ac
|
|
@ -34,6 +34,7 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<button onclick="enableGravity">Enable Gravity</button>
|
||||||
<folk-shape id="box1" x="100" y="100" width="30" height="30"></folk-shape>
|
<folk-shape id="box1" x="100" y="100" width="30" height="30"></folk-shape>
|
||||||
<folk-shape id="box2" x="200" y="350">Hello World</folk-shape>
|
<folk-shape id="box2" x="200" y="350">Hello World</folk-shape>
|
||||||
<folk-event-propagator
|
<folk-event-propagator
|
||||||
|
|
@ -62,12 +63,24 @@ rotation: from.x"
|
||||||
|
|
||||||
const ropes = Array.from(document.querySelectorAll('folk-event-propagator'));
|
const ropes = Array.from(document.querySelectorAll('folk-event-propagator'));
|
||||||
|
|
||||||
DeviceOrientationEvent?.requestPermission();
|
function onDeviceOrientation(e) {
|
||||||
|
|
||||||
window.addEventListener("deviceorientation", (event) => {
|
|
||||||
console.log(event);
|
console.log(event);
|
||||||
// ropes.forEach(rope => { rope.gravity = { x: 0, y: 0} })
|
// ropes.forEach(rope => { rope.gravity = { x: 0, y: 0} })
|
||||||
});
|
}
|
||||||
|
|
||||||
|
async function enableGravity() {
|
||||||
|
if (DeviceOrientationEvent.requestPermission) {
|
||||||
|
const permission = await DeviceOrientationEvent.requestPermission();
|
||||||
|
|
||||||
|
if (permission === "granted") {
|
||||||
|
window.addEventListener("deviceorientation", onDeviceOrientation);
|
||||||
|
} else {
|
||||||
|
console.warn('Permission for device orientation rejected', permission)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
window.addEventListener("deviceorientation", onDeviceOrientation);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue