• <bdo id='duE42'></bdo><ul id='duE42'></ul>
    <legend id='duE42'><style id='duE42'><dir id='duE42'><q id='duE42'></q></dir></style></legend>

  • <i id='duE42'><tr id='duE42'><dt id='duE42'><q id='duE42'><span id='duE42'><b id='duE42'><form id='duE42'><ins id='duE42'></ins><ul id='duE42'></ul><sub id='duE42'></sub></form><legend id='duE42'></legend><bdo id='duE42'><pre id='duE42'><center id='duE42'></center></pre></bdo></b><th id='duE42'></th></span></q></dt></tr></i><div id='duE42'><tfoot id='duE42'></tfoot><dl id='duE42'><fieldset id='duE42'></fieldset></dl></div>

        <small id='duE42'></small><noframes id='duE42'>

      1. <tfoot id='duE42'></tfoot>

        Jquery UI Draggable:将助手对齐到鼠标位置

        时间:2024-04-19
          <tfoot id='XdkRQ'></tfoot>
            <bdo id='XdkRQ'></bdo><ul id='XdkRQ'></ul>
              <tbody id='XdkRQ'></tbody>
          • <i id='XdkRQ'><tr id='XdkRQ'><dt id='XdkRQ'><q id='XdkRQ'><span id='XdkRQ'><b id='XdkRQ'><form id='XdkRQ'><ins id='XdkRQ'></ins><ul id='XdkRQ'></ul><sub id='XdkRQ'></sub></form><legend id='XdkRQ'></legend><bdo id='XdkRQ'><pre id='XdkRQ'><center id='XdkRQ'></center></pre></bdo></b><th id='XdkRQ'></th></span></q></dt></tr></i><div id='XdkRQ'><tfoot id='XdkRQ'></tfoot><dl id='XdkRQ'><fieldset id='XdkRQ'></fieldset></dl></div>

              <legend id='XdkRQ'><style id='XdkRQ'><dir id='XdkRQ'><q id='XdkRQ'></q></dir></style></legend>

              • <small id='XdkRQ'></small><noframes id='XdkRQ'>

                  本文介绍了Jquery UI Draggable:将助手对齐到鼠标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用 jQuery,我有一个可拖动的元素.这是一个大小为 200 x 40 的 div.当然,用户可以通过点击 div 中的不同位置来开始拖动这个 div.我想要的是当 startdrag 事件发生时,帮助器(克隆)div 将始终以相同的方式与光标对齐,无论用户在 div 中的哪个位置开始拖动.

                  With jQuery I have a draggable element. It's a div with a size of 200 x 40. Of course the user can start dragging this div by clicking at variuos positions in the div. What I want is when the startdrag event happens, the helper (clone) div will always be aligned to the cursor the same way, no matter where in the div the user started dragging.

                  所以在 mousedown 之后,助手的 top 和 left 值需要与鼠标 x 和 y 相同.我用这个咖啡脚本代码试过这个:

                  So after the mousedown the helper's top and left values need to be the same as the mouses x and y. I've tried this using this coffeescript code:

                  onStartDrag: ( e, ui ) =>
                      ui.helper.css
                          left: e.clientX
                          top: e.clientY
                  
                      console.log( e )
                  

                  但这不起作用,我猜这是因为我输入的值由于鼠标移动而直接被可拖动插件覆盖..

                  But it doesn't work and my guess is that this is happening because the values I put in are directly overwritten by the draggable plugin because of mouse movement..

                  有什么想法吗?

                  推荐答案

                  在尝试了 Amar 的答案后,发现它搞砸了与 droppable 的交互,我深入挖掘,发现有一个专门的选项支持这个称为 cursorAt.

                  After trying Amar's answer and realizing that it screws up interactions with droppable, I dug deeper, and found that there is an option specifically to support this called cursorAt.

                  $('blah').draggable
                    helper: ->
                      ... custom helper ...
                    cursorAt:
                      top: 5
                      left: 5
                  

                  这会将助手的左上角放置在光标左上方 5 个像素处,并与 droppable 正确交互.

                  This places the top-left corner of the helper 5 pixels above and to the left of the cursor, and interacts correctly with droppable.

                  http://api.jqueryui.com/draggable/#option-cursorAt

                  让我们在应得的地方给予信任.谢谢,jquery-ui 邮件列表存档!

                  And let's give credit where credit is due. Thanks, jquery-ui mailing list archives!

                  https://groups.google.com/forum/#!topic/jquery-ui/Evb94G_QvNw

                  这篇关于Jquery UI Draggable:将助手对齐到鼠标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:非法的继续声明? 下一篇:早午餐如何禁用 RequireJS 模块包装

                  相关文章

                  <i id='cuPO0'><tr id='cuPO0'><dt id='cuPO0'><q id='cuPO0'><span id='cuPO0'><b id='cuPO0'><form id='cuPO0'><ins id='cuPO0'></ins><ul id='cuPO0'></ul><sub id='cuPO0'></sub></form><legend id='cuPO0'></legend><bdo id='cuPO0'><pre id='cuPO0'><center id='cuPO0'></center></pre></bdo></b><th id='cuPO0'></th></span></q></dt></tr></i><div id='cuPO0'><tfoot id='cuPO0'></tfoot><dl id='cuPO0'><fieldset id='cuPO0'></fieldset></dl></div>
                • <tfoot id='cuPO0'></tfoot>
                • <legend id='cuPO0'><style id='cuPO0'><dir id='cuPO0'><q id='cuPO0'></q></dir></style></legend>
                    <bdo id='cuPO0'></bdo><ul id='cuPO0'></ul>

                    <small id='cuPO0'></small><noframes id='cuPO0'>