自定义事件
MouseEvent 接口指用户与指针设备(如鼠标)交互时发生的事件。
由于initMouseEvent方法被摒弃
,使用MouseEvent的构造函数方法
最初
let event = document.createEvent('MouseEvents')
event.initMouseEvent(
type,
canBubble,
cancelable,
view,
detail,
screenX,
screenY,
clientX,
clientY,
ctrlKey,
altKey,
shiftKey,
metaKey,
button,
relatedTarget);
// 触发
Dom.dispatchEvent(event)
代替
const event = new MouseEvent('mousedown', {
bubbles: true,
cancelable: true,
view: window,
detail: 0,
screenX: 0,
screenY: 0,
clientX: 0,
clientY: 0,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
button:0,
relatedTarget: null,
});
// 触发
Dom.dispatchEvent(event)