jquery调用拖拽事件的方法

发布于 2024-09-28 03:43:32 字数 572 浏览 3 评论 0原文

我的代码有一些根据不同操作出现在屏幕上的 div。 div 有句柄,可以通过 jquery ui.draggable 代码拖动它们。我设置了可拖动 ui 堆栈选项,这样当您拖动某个项目时,它会自动移动到所有其他可拖动项目的前面。

我遇到的问题是,即使您只需单击手柄,而不将其拖动到任何地方,我也希望将 div 移动到前面。我尝试过在单击手柄时触发各种事件,例如 mousedown、mousemove、mouseup、drag、dragstart 和 Dragstop,但似乎都没有成功。我也尝试过仅更改 z-index 值,但到目前为止效果不佳。

我的代码看起来像这样。假设我有 div,句柄是 h5 标签。我已经实例化了可拖动功能。所以我有:

$("div.window h5").click(function() {
   $(this).parents("div:first").trigger("whatever event i am trying");
)};

但这不起作用。 (我还尝试将触发器放在 h5 本身而不是父 div 上)。我没有看到错误,我只是没有得到想要的结果。

预先感谢您的任何帮助!

My code has some divs that appear on the screen based on different actions. The divs have handles that make them draggable via the jquery ui.draggable code. I have the draggable ui stack option set, so that when you drag an item, it automatically moves to the front of all other draggable items.

The problem I am having is that I want a div moved to the front even if you just click on the handle, without dragging it anywhere. I've tried triggering various events when the handle is clicked, such as mousedown, mousemove, mouseup, drag, dragstart and dragstop, but none seem to do the trick. I've also tried just changing the z-index values, but that also hasn't worked well so far.

My code looks something like this. Say I have the div, and the handle is an h5 tag. I have instantiated the draggable function already. So I have:

$("div.window h5").click(function() {
   $(this).parents("div:first").trigger("whatever event i am trying");
)};

But this isn't working. (I've also tried putting the trigger on the h5 itself instead of the parent div). I am not seeing an errors, I am just not getting the desired result.

Thanks in advance for any help!

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

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

发布评论

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

评论(1

浅浅 2024-10-05 03:43:32

试试这个:

$("div.window h5").click(function(e){

   // Variable to hold the highest z-index
   var largestZ = 1; 

   // I have used div.window h5 but this should cycle through each draggable element
   $("div.window h5").each(function(i) {
      // Get the the z-index and update if it is larger than current largest value
      var currentZ = parseFloat($(this).css("zIndex"));
      largestZ = currentZ > largestZ ? currentZ : largestZ;
   });

   $(this).css("z-index", largestZ + 1);
});

一些选择器可能需要更改,因为我看不到您的完整代码。我找到了这个片段并从此处修改了它。

Try this:

$("div.window h5").click(function(e){

   // Variable to hold the highest z-index
   var largestZ = 1; 

   // I have used div.window h5 but this should cycle through each draggable element
   $("div.window h5").each(function(i) {
      // Get the the z-index and update if it is larger than current largest value
      var currentZ = parseFloat($(this).css("zIndex"));
      largestZ = currentZ > largestZ ? currentZ : largestZ;
   });

   $(this).css("z-index", largestZ + 1);
});

Some of the selectors might need to change because I can't see your full code. I found this snippet and modified it from here.

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