Context Menu Event
By configuring the onContextMenu
parameter, you can listen to the right-click events of elements
and execute corresponding callback functions.
Usage Example
Below is an example showing how to handle right-click event interactions using the iCraft Player component.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self';
script-src 'self' 'unsafe-inline' 'unsafe-eval' https://unpkg.com blob:;
worker-src blob: 'self';
style-src 'self' 'unsafe-inline';
img-src 'self' data: blob:;
font-src 'self' blob:;
connect-src 'self' https://icraft.gantcloud.com blob:;
object-src 'none';
base-uri 'self';
form-action 'self';
frame-src 'self';
"
/>
<title>ICraft Player Click Demo</title>
<style>
body {
margin: 0;
padding: 0;
}
#container {
width: 100%;
height: 100vh;
position: relative;
}
#text {
position: absolute;
bottom: 10px;
right: 10px;
}
</style>
<script src="https://unpkg.com/@icraft/player@latest/dist/umd/icraft-player.min.js"></script>
</head>
<body>
<div id="container">
<div id="text"></div>
</div>
</body>
<script>
const player = new ICraftPlayer({
src: "/api/static/templates/AWSCloud.iplayer",
container: document.getElementById("container"),
onContextMenu: (e) => {
console.log(e);
const { instance: element } = e;
const name = element?.options?.name || "";
document.getElementById("text").innerText = "Right Clicked:" + name;
},
});
</script>
</html>
API
Name | Description | Type | Default | Required |
---|---|---|---|---|
onContextMenu | Right-click event callback | (params: MouseEventParams) => void | undefined | false |
MouseEventParams
interface MouseEventParams {
instance: Element3D | null;
event: MouseEvent;
data: OptionsType | null;
}