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);
}
}