6. Fabric 拖拽元素到画布

监听元素是否被下放到画布上

canvas.on('drop', elt => {
   // 画布元素距离浏览器左侧和顶部的距离
   let offset = {
     left: canvas.getSelectionElement().getBoundingClientRect().left,
     top: canvas.getSelectionElement().getBoundingClientRect().top
   }
   // 鼠标坐标转换成画布的坐标(未经过缩放和平移的坐标)
   let point = {
     x: elt.e.x - offset.left,
     y: elt.e.y - offset.top,
   }
  // 转换后的坐标,restorePointerVpt 不受视窗变换的影响
  let pointerVpt = this.canvas.restorePointerVpt(point)
  //创建元素
  // createElement()
});

你可能感兴趣的:(Fabric,fabric,前端,javascript)