我试图弄清楚如何将图像从一个画布拖放到另一个画布.假设画布彼此相邻,是否可以无缝地将某些东西拖过边界?如果没有,将 div 拖到画布上,获取其 ID,然后通过响应画布上的 mouseup 位置来放置它是不是更好?
I'm trying to figure out how to drag and drop an image from one canvas to another canvas. Assuming the canvases are next to each other, would it be possible to seamlessly drag something across the border? If not, is it a better idea to drag a div over the canvas, get its ID, and place it by responding to the mouseup location on the canvas?
不要在画布上拖动项目.画布是一种非保留模式(或即时模式) 图形 API.您发出绘图命令并获得像素.模拟拖动包括跟踪用户的鼠标移动并选择反复清除并使用不同参数重新绘制画布,以使某些像素子集看起来像一个有凝聚力的对象一样移动.
You don't drag items on a canvas. A canvas is a non-retained mode (or immediate mode) graphics API. You issue draw commands and you get pixels. Simulating dragging is comprised of tracking the user's mouse movements and choosing to repeatedly clear and re-draw the canvas with different parameters to make some subset of the pixels appear to move as a cohesive object.
将此与 HTML 或 SVG 进行对比,在其中您实际上更改了真实 DOM 对象的位置/变换属性,并且当您的文档的视觉表示自动更新时,手表会自动更新.
如果你有两个画布并且想要从一个画布拖动到另一个画布,我会做的是:
If you have two canvases and want to drag something from one to the other, what I would do is:
mousemove
事件,并更新画布相对于鼠标的位置.mousemove
event on the document, and update the position of the canvas relative to the mouse.不过,我在这里可能真正要做的是使用 SVG.;)
Though, what I'd probably really do here is use SVG. ;)
这篇关于如何从一个 HTML5 画布拖放到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!