Dojo dnd:头像定位

发布于 2024-07-29 19:21:01 字数 158 浏览 7 评论 0原文

是否可以使用dojo工具包的dnd api更改头像的位置? 此时,拖动时,被拖动项目的头像出现在鼠标光标的右侧和下方。 我希望它与鼠标光标位于同一位置。 我对我的应用程序进行了一些可用性测试,大多数人似乎尝试尝试将头像拖到放置区域中,而不是将光标移动到放置区域上。 任何输入都会很好。 谢谢!

Is it possible to change the positioning of the avatar with dojo toolkit's dnd api? At the moment, when dragging, the avatar of the dragged item appears to the right and below the mouse cursor. I want it to be in the same position as the mouse cursor. I ran some usability tests on my application, and most people seem to attempt to try and drag the avatar into the drop area, as opposed to moving the cursor over the drop area. Any input would be nice. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彡翼 2024-08-05 19:21:01

抱歉,由于技术原因不可能。

更新:根据流行的要求,这些是技术原因:

  • 当鼠标正下方有一个节点时,该节点会获取所有鼠标事件。
  • 鼠标事件在父链上冒泡。
  • 现在想象一下,您用鼠标移动该节点 - 该节点将始终获得所有鼠标事件。
  • 这意味着任何其他节点(例如目标)无法获取鼠标事件,除非它是移动节点的父节点。 通常情况并非如此。

但我知道其他人也能做到! 应该是可以的! 是的,这是可能的……原则上:

  • 让我们注册所有目标节点。
  • 让我们直接在最顶层的父级(文档)上捕获相关的鼠标移动事件。
  • 当我们检测到拖动操作时,我们执行以下操作:
    1. 计算所有目标的几何形状(边界框)。
    2. 每次鼠标移动时,我们都会检查当前鼠标位置是否与目标重叠。 “A+”学生的奖励分:检测与其他节点的重叠,例如,当目标因美观原因而部分模糊时,并正确处理这种情况。
    3. 如果当前鼠标位置与目标重叠,让我们启动“可以放下”操作,例如,显示一些提示,以便最终用户知道她现在可以放下。

为什么Dojo不这样做? 由于多种技术原因(我们终于做到了!):

  • 在大多数浏览器中,节点的几何计算都是出了名的错误。 一旦涉及表格或任何其他重要的放置方式,您就无法 100% 确定边界框是正确的。
  • 几何计算是一项昂贵的操作,假设在拖动操作期间不能进行任何更改(情况并非总是如此),我们必须对所有目标的每个拖动操作至少执行一次。 浏览器可能会出于多种原因回流节点⇒它可以移动/调整现有目标的大小,因此我们必须保持警惕。
  • 通常,计算出的框保存在一个列表中⇒检查列表中的交集是O(n)(线性)⇒随着目标数量的增长不能很好地扩展。
  • 所有鼠标事件处理程序都应该很快,否则浏览器的鼠标事件处理工具可能会“损坏”,从而导致不可预测的副作用。 请参阅前面的几点,了解鼠标事件处理速度缓慢的原因。
  • 改进线性搜索是可能的,例如,可以使用 2D 空间树,但它会导致更多(更多)JavaScript 代码⇒ 在客户端下载更多内容⇒ 通常这是不值得的。

我怎么知道呢? 因为 Dojo 在早期版本中曾经有过这种拖放操作,所以我们遇到了我上面描述的令人厌烦的问题。 任何改进都是一场艰苦的战斗,这会增加代码大小。 最后,我们决定不重新发明和复制浏览器中已经内置的机制。 浏览器实际上执行相同的工作:计算节点的几何形状,查找底层节点,并适当地调度鼠标移动事件。

当前的实现不使用鼠标移动事件,也不计算几何图形。 相反,它依赖于开始拖动后目标检测到的鼠标悬停/移出事件。 它工作可靠并且可扩展性良好。

这个故事中的另一个问题是:Dojo 将目标视为容器——这是一个非常常见的用例(购物车、重新排列项目、编辑层次结构)。 目前已实现线性容器和通用树,也可以自定义容器。 拖放时,您可以看到拖动的项目并将其放置在目标容器内的适当位置,例如,将它们插入现有项目之间。 使用几何计算和检查来实现此功能将非常昂贵。

Sorry, not possible for technical reasons.

UPDATE: by popular demands these are technical reasons:

  • When you have a node right under the mouse, the node gets all mouse events.
  • The mouse events bubble up the parent chain.
  • Now imagine that you move this node with the mouse — this node would always get all mouse events.
  • It means that any other node, e.g., a target cannot get mouse events unless it is a parent of the moved node. Typically this is not the case.

But I know that other people can do it! It should be possible! Yes, it is possible … in principle:

  • Let's register all target nodes.
  • Let's catch relevant mouse move events directly on the topmost parent (the document).
  • When we detect a drag operation, let's do the following:
    1. Calculate geometry (bounding boxes) of all targets.
    2. On every mouse move lets check if the current mouse position overlaps with a target. Bonus points for an "A+" student: detect overlaps with other nodes, e.g, when a target is partially obscure for cosmetic reasons, and process this situation correctly.
    3. If the current mouse position overlaps with a target, let's initiate "drop is possible" actions, e.g., show some cues so the end user knows that she can drop now.

Why Dojo doesn't do that? For a number of technical reasons (finally we got there!):

  • A node's geometry calculations are notoriously buggy in most browsers. As soon as tables are involved, or any other non-trivial means of placement, you cannot be 100% sure that the bounding box is correct.
  • Geometry calculations is an expensive operation, and we have to do it at least once on every drag operation for all targets assuming that no changes can be made during the drag operation (not always the case). A browser may reflow nodes for many reasons ⇒ it can move/resize existing targets, so we have to be vigilant.
  • Typically the calculated boxes are kept in a list ⇒ checking the list for intersections is O(n) (linear) ⇒ doesn't scale well as number of targets grow.
  • All mouse event handlers should be fast, otherwise a browser's mouse event handling facility can be "broken" leading to unpredictable side-effects. See the previous points for reasons why mouse event processing can be slow.
  • Improving on the linear search is possible, e.g., 2D spatial trees can be used, but it leads to more (much more) JavaScript code ⇒ more stuff to download on the client side ⇒ typically it isn't worth it.

How do I know that? Because Dojo used to have this kind of drag'n'drop in earlier versions, and we got sick and tired fighting problems I described above. Any improvement was an uphill battle, which increased the code size. Finally we decided against reinventing and replicating mechanisms already built in a browser. A browser does virtually the same work: calculates geometry of nodes, finds the underlying node, and dispatches a mouse move event appropriately.

The current implementation doesn't use mouse move events and do not calculate the geometry. Instead it relies on mouse over/out events detected by targets after a drag was started. It works reliably and scales well.

Another wrinkle in this story: Dojo treats targets as containers — a very common use case (shopping carts, rearranging items, editing hierarchies). Linear containers and generic trees are implemented at the moment, custom containers are possible. When dragging and dropping you can see and drop dragged items in a proper position within a target container, e.g., inserting them between existing items. Implementing this feature using geometric calculations and checks would be prohibitively expensive.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文