jQuery UI可拖动,停止拖动,但以其他方式拖动 [英] jQuery UI draggable, stop drag but let dragging the other way

查看:89
本文介绍了jQuery UI可拖动,停止拖动,但以其他方式拖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题很简单,看看这个

$("#element").draggable({
    axis: "x",
    drag: function(event, obj){
        if(condition)
            return false;
    }
});

如您所见,条件是否为真,除非您释放并再次按下鼠标键,否则拖动将停止,并且无法继续向任何方向拖动.

As you can see if condition is true dragging will be stopped and it won't be possible to continue dragging to any direction unless mouse key is released and pressed again.

所以问题是如何在不停止向其他方向拖动的情况下停止用户向某个方向拖动元素?

So the question is how can I stop user dragging element to some direction without stopping drag to any other directions?

推荐答案

尝试一下,只需将位置重置为0.

Try this, just reset back the position to 0.

$(function() {
    $( "#draggable" ).draggable({ 
        axis: "y",
        drag: function(event, obj){
            if(obj.position.top > 0){
               obj.position.top = 0;
            }
        },

    });

 });

请参见演示此处

这篇关于jQuery UI可拖动,停止拖动,但以其他方式拖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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