jQuery UI可调整大小的快照 [英] jQuery UI resizable snap to size

查看:146
本文介绍了jQuery UI可调整大小的快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可调整大小的左侧导航栏.默认宽度为200,我希望缩放器捕捉到该宽度.目前,我有一个if子句,可以正常工作,但是我不知道如何以编程方式捕捉到该宽度.

I have a left-side navigation which is resizable. The default width is 200 and I want the resizer to snap to that width. Currently I have this if-clause which is working fine but I don't know how to snap to that width programmatically.

resize: function (event, ui) {
    if(Math.abs(200 - ui.size.width) <= 20){
        // snap to 200 width
    }
}

如果有人可以在这里帮助我,那将是很棒的:)

Would be great if someone could help me here :)

推荐答案

确定成功了.只需将元素的宽度设置为200.它的公差为15px,因此,如果元素在185和215px之间,它将捕捉到200px.

Ok got it working. Simply set the width of the element to 200. It has a tolerance of 15px so if the element is between 185 and 215px it will snap to 200px.

$("#left").resizable({
minWidth: 60,
handles: "e",
resize: function (event, ui) {
    if(Math.abs(200 - ui.size.width) <= 15){
        $("#left").css("width", 200);
    }
}

这篇关于jQuery UI可调整大小的快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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