简体   繁体   English

Flex拖放

[英]Flex Drag and Drop

I have an image that I show inside a canvas which I can zoom in on. 我有一个显示在画布上的图像,可以放大。 The problem is that when zoomed in, I try to drag the image, I can see the outline of the image in the foreground, (ie) outside the canvas boundary. 问题在于,当放大时,我尝试拖动图像,可以在前景(即,画布边界之外)中看到图像的轮廓。 Is there anyway to tell the dragHandler to crop the "grabbed" image outside the canvas boundary? 无论如何,有什么要告诉dragHandler在画布边界之外裁剪“被抓”的图像吗?

In my experience using the built in drag/drop flex stuff is overkill for something that involves moving a component around in a canvas. 以我的经验,使用内置的拖放Flex东西对于涉及在画布中移动组件的东西来说是过大的。

The easier way to do this (in my opinion) would be to listen for mouse down/up/move the image around in the canvas yourself. (我认为)更简单的方法是自己听鼠标向下/向上/移动画布中的图像。

When you detect a mouse down on your image, add a listener for mouse move (pro tip: make sure you set useCapture to true when calling addEventListener) and store the position of the mouse relative the origin of your image. 当您在图像上检测到鼠标向下时,请添加鼠标移动侦听器(提示:请确保在调用addEventListener时将useCapture设置为true),并存储鼠标相对于图像原点的位置。 Then whenever you get a mouse move, change the position of your image within your canvas taking into account the position of the mouse within the image (which you stored on mouse down). 然后,每当您移动鼠标时,请考虑在图像中鼠标的位置(将其存储在鼠标下方),更改图像在画布中的位置。 Keep doing this until mouse up occurs, then remove your mouse move listener. 继续执行此操作,直到发生鼠标上移,然后删除鼠标移动侦听器。

There are some additional finer points to account for (what if the user drags outside of the canvas? Or outside of the browser window?), but this will get you started. 还需要考虑一些其他方面(如果用户将其拖到画布之外还是在浏览器窗口之外?),但这将使您入门。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM