穿透dom觸發事件

const elems = document.elementsFromPoint(e.pageX, e.pageY);
const instance = elems.filter(elem => elem.classList.contains('meeting-hover-card'));
   if (instance.length > 0) {
           this.instance = instance[0];
           this.fireEvent(this.instance, 'mouseover');
    }

  使用document.elementsFromPoint能穿透獲取dom節點,經過dispatchEvent模擬事件javascript

 const evObj = document.createEvent('Events');
    evObj.initEvent(eventName, true, false);
    elem.dispatchEvent(evObj);
相關文章
相關標籤/搜索