jquery ui:可拖动 ->如果拖动取消绑定悬停事件?

发布于 2024-09-04 09:26:19 字数 838 浏览 3 评论 0原文

我有一个相当奇怪的问题,应该修复我当前项目中的错误。我正在处理网页上随机放置的许多缩略图。所有拇指都有一个绝对位置。 这个拇指对 jquery 设置的悬停做出反应:

$(".thumb").hover(
  function () {
    $(this).stop().animate({"height": full}, "fast");
    $(this).css('z-index', z);
    z++;        
  },
  function () {
    $(this).stop().animate({"height": small}, "fast");
  }

因此悬停时它们会调整到特定高度。 此外,所有这些拇指都可以通过 jquery ui-draggable 插件进行拖动。

我想知道如果当前拖动了拇指,是否可以解除这些拇指的悬停绑定!

$( ".thumb" ).bind( "dragstart", function() {
      //$(this).draggable( "disable" );
      $(this).unbind('mouseenter mouseleave');
    });
    $( ".thumb" ).bind( "dragstop", function() {
        //$(this).draggable( "enable" );
        $(this).bind('mouseenter mouseleave');
    });

目前这不起作用。如果我当前正在拖动拇指,我只想禁用悬停事件。在 Dragstop 上,悬停应该再次起作用。

知道我该如何解决这个问题吗?谢谢

i have a rather weird problem that should fix a bug in my current project. I'm working with a lot of thumbnails randomly positioned on the webpage. all thumbs have an absolute position.
this thumbs react on a hover set by jquery:

$(".thumb").hover(
  function () {
    $(this).stop().animate({"height": full}, "fast");
    $(this).css('z-index', z);
    z++;        
  },
  function () {
    $(this).stop().animate({"height": small}, "fast");
  }

so on hover they resize to a specific height.
Moreover all these thumbs are draggable via the jquery ui-draggable plugin.

I wonder if it is possible to UNBIND the hover of these thumbs if a thumb is currently dragged!

$( ".thumb" ).bind( "dragstart", function() {
      //$(this).draggable( "disable" );
      $(this).unbind('mouseenter mouseleave');
    });
    $( ".thumb" ).bind( "dragstop", function() {
        //$(this).draggable( "enable" );
        $(this).bind('mouseenter mouseleave');
    });

this is not working at the moment. I simply want to disable the hover event if i'm currently dragging a thumb. On dragstop the hover should work again.

Any idea how i could solve this? thank you

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

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

发布评论

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

评论(2

悲喜皆因你 2024-09-11 09:26:19

mousedownmouseup 怎么样。

$( ".thumb" ).bind( "mousedown", function() {
  //$(this).draggable( "disable" );
  $(this).unbind('mouseenter mouseleave');
});
$( ".thumb" ).bind( "mouseup", function() {
    //$(this).draggable( "enable" );
    $(this).bind('mouseenter mouseleave');
});

虽然我不确定你解除绑定的目的。可能还有另一种方法。无论如何,mousedownmouseup 应该触发拖动的开始和停止。

请记住,如果用户进行正常的点击,则处理程序每​​次都会被绑定和解除绑定。

How about mousedown and mouseup.

$( ".thumb" ).bind( "mousedown", function() {
  //$(this).draggable( "disable" );
  $(this).unbind('mouseenter mouseleave');
});
$( ".thumb" ).bind( "mouseup", function() {
    //$(this).draggable( "enable" );
    $(this).bind('mouseenter mouseleave');
});

Although I'm not sure the purpose of your unbinding. There may be another way. Anyway, the mousedown and mouseup should trigger the start and stop of your drag.

Just remember, if a user does a normal click, the handlers will be bound and unbound every time.

离不开的别离 2024-09-11 09:26:19

目的是,如果我将一个缩略图非常快地拖动到另一个缩略图上,鼠标就会离开当前缩略图,并触发另一个缩略图的悬停。这实际上是一个相当有问题的效果。所以我想知道如何解决这个问题!

我的网站的用户界面是这样工作的:如果我滚动缩略图,它会分层在顶部(z-index++),缩略图会调整大小一点,并且可以拖动。因此,目前,如果我的网页上随机出现 10 个拇指,并且我将它们拖动得非常快,那么它可以正常工作,但不知怎的,感觉有点错误,因为如果我拖动图像太快,则拖动的图像不会真正跟随鼠标的速度 - 因此会触发悬停。因此,我想禁用除当前拖动的之外的所有拇指设置的所有内容(悬停事件和拖动能力)。我知道听起来很复杂! ;)也许有人明白了!

the purpose is that if i drag a thumbnail very fast over another one, the mouse leaves the current-thumbnail and it triggers the hover of another thumbnail. this is actually a rather buggy effect. so i wonder how i could solve this problem!

the UI of my website works like this: If i rollover a thumbnail it gets layered on top (z-index++), the thumbnail gets resized a little bit bigger and it's draggable. So currently if there lie like 10 thumbs randomly on my webpage and i drag them around really fast it works properly but somehow it feels a little bit buggy due to the fact that if i drag the images too fast the dragged image doesn't really follow the speed of the mouse - so a hover-out is triggered. Therefore i want to disable EVERYTHING set with jquery (hover event, and the abilty to drag) from all thumbs except of the current dragged one. sounds complicated i know! ;) maybe someone gets it!

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