Commit c8aa46a5 by xinla

fabric v4至v5事件兼容升级及优化

1 parent d7f71b0a
...@@ -521,7 +521,7 @@ export default { ...@@ -521,7 +521,7 @@ export default {
} }
this.setPosterBackgroundImage() this.setPosterBackgroundImage()
// 删除某个图层 // 删除图层按钮
let deleteBtn = document.getElementById('deleteBtn') let deleteBtn = document.getElementById('deleteBtn')
function addDeleteBtn(x, y) { function addDeleteBtn(x, y) {
...@@ -532,10 +532,15 @@ export default { ...@@ -532,10 +532,15 @@ export default {
} }
canvas.on('selection:created', function (e) { canvas.on('selection:created', function (e) {
addDeleteBtn(e.target.lineCoords.tr.x, e.target.lineCoords.tr.y) addDeleteBtn(e.selected[0].lineCoords.tr.x, e.selected[0].lineCoords.tr.y)
}) })
canvas.on('selection:updated', function (e) { canvas.on('selection:updated', function (e) {
addDeleteBtn(e.target.lineCoords.tr.x, e.target.lineCoords.tr.y) let activeObject = canvas.getActiveObject()
if (activeObject._objects?.length > 1) {
deleteBtn.style.display = 'none'
} else {
addDeleteBtn(e.selected[0].lineCoords.tr.x, e.selected[0].lineCoords.tr.y)
}
}) })
//通用事件另外写法 //通用事件另外写法
...@@ -620,21 +625,20 @@ export default { ...@@ -620,21 +625,20 @@ export default {
}) })
// alt键缩放 // alt键缩放
document.getElementById('canvas-wrap').addEventListener('wheel', (e) => { // document.getElementById('canvas-wrap').addEventListener('wheel', (e) => {
// e.stopPropagation() // // e.stopPropagation()
if (e.altKey) { // if (e.altKey) {
e.preventDefault() // e.preventDefault()
console.log(e) // console.log(e)
let zoom = (e.deltaY > 0 ? 0.1 : -0.1) + canvas.getZoom() // let zoom = (e.deltaY > 0 ? 0.1 : -0.1) + canvas.getZoom()
zoom = Math.max(0.1, zoom) //最小为原来的1/10 // zoom = Math.max(0.1, zoom) //最小为原来的1/10
zoom = Math.min(5, zoom) //最大是原来的5倍 // zoom = Math.min(5, zoom) //最大是原来的5倍
let zoomPoint = new fabric.Point(e.offsetX, e.offsetY) // let zoomPoint = new fabric.Point(e.offsetX, e.offsetY)
canvas.zoomToPoint(zoomPoint, zoom) // canvas.zoomToPoint(zoomPoint, zoom)
} // }
}) // })
deleteBtn.addEventListener('click', () => { deleteBtn.addEventListener('click', () => {
let activeObject = canvas.getActiveObject()
if (activeObject) { if (activeObject) {
this.$confirm('是否确认删除吗?', '警告', { this.$confirm('是否确认删除吗?', '警告', {
confirmButtonText: '确定', confirmButtonText: '确定',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!