点击事件
通过配置 onClick
参数,可以监听元素的点击事件,并执行相应的回调函数。
使用示例
下面是一个示例,展示了如何使用 iCraft Player 组件进行元素点击事件交互。
import React, { useState } from "react";
import { ClickParams, ICraftPlayer } from "@icraft/player-react";
export default () => {
const [clicked, setClicked] = useState<string>();
const onClick = (e: ClickParams) => {
console.log(e);
const { instance: element } = e;
setClicked(element?.options?.name || "");
};
return (
<div style={style}>
<ICraftPlayer
src='/templates/AWSCloud.iplayer'
onClick={onClick}
/>
<div style={textStyle}>Clicked: {clicked}</div>
</div>
);
};
const style = {
width: "100%",
height: "100%",
position: "relative" as const,
overflow: "hidden" as const,
};
const textStyle = {
position: "absolute" as const,
bottom: 10,
right: 10,
};
API
Name | description | type | default | required |
---|---|---|---|---|
onClick | 点击事件回调 | (params: ClickParams) => void | undefined | false |
ClickParams
interface ClickParams {
instance: Element3D | null;
event: MouseEvent;
data: OptionsType | null;
}