触发('mouseup')以编程方式停止拖动的替代方法 [英] Alternatives to trigger('mouseup') to stop dragging programmatically

查看:82
本文介绍了触发('mouseup')以编程方式停止拖动的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我在jquery中发现了一个错误:

触发 mouseup时,jquery的可拖动引发错误
是否可以在不使用触发器的情况下实现以下功能获得一些建议?
我希望能够在达到条件时停止拖动元素,我一直在尝试很多可能性,但没有一种自动运行,即使事件在条件为true时触发,它仅在以下情况下生效您鼠标拖动。
我真的很受困于此,我们将不胜感激。
PD:我已经在jquery.ui中发布了该错误

As it seems like I have found a bug in jquery:
jquery draggable throws error when 'mouseup' is triggered Can I get some advice on how to implement the following functionality without using the trigger? I want to be able to stop an element to be dragged when a condition has been reached, I have been trying lot's of possibilities but none works automatically, even though the event is fired when condition is true it only takes effect when you "mouseup" the dragger. I'm really trapped on this, any help will be very appreciated. P.D: I have already posted the bug in jquery.ui

推荐答案

以下代码对我来说很有效。没有任何方法可以仅取消一个拖动,但是可以使用ui.position设置对象的位置。

The following piece of code worked for me well. There isn't any method that cancels only one "dragging", but you can set the position of the object using ui.position

$('#draggablediv').draggable({
        drag: function (event, ui) {
            if (your_condition) { // for example: ui.position.left < 100
                ui.position.left = ui.position.left_old
                ui.position.top = ui.position.top_old
            }
            ui.position.left_old = ui.position.left
            ui.position.top_old = ui.position.top
        }
    })

这篇关于触发('mouseup')以编程方式停止拖动的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆