初始化后无法应用JqueryUI可调整大小的AspectRatio吗? [英] Unable to apply JqueryUI Resizable AspectRatio after initialization?
问题描述
我试图以可调整大小的JQueryUI动态地打开/关闭纵横比,但是即使将选项设置为false,它仍会保持纵横比.以下是我目前正在使用的代码:
I was trying to turn the aspect ratios on/off dynamically in JQueryUI resizable, however even after setting the option to false, it keeps maintaining the aspect ratio. Below is the code I am currently working with:
$('#aspect_check').click( function() {
var ischecked = $('#aspect_check').prop('checked');
if (ischecked) {
$( "#resizable" ).resizable( "option", "aspectRatio", .75);
} else {
$( "#resizable" ).resizable( "option", "aspectRatio", false );
}
});
我发现了3年前的错误报告,尽管将其标记为关键,但似乎仍未得到修复. http://bugs.jqueryui.com/ticket/4186
I found a bug report from 3 years ago, which looks like it still hasn't been fixed despite marking it critical. http://bugs.jqueryui.com/ticket/4186
该变通办法不适用于最新版本.有什么想法吗?
The workarounds don't work with the latest versions. Any ideas?
经过大量的错误报告后,这里是一种解决方法:
After going through a lot of bug reports, here is a work around:
$(function() {
$.extend($.ui.resizable.prototype, (function (orig) {
return {
_mouseStart: function (event) {
this._aspectRatio = !!(this.options.aspectRatio);
return(orig.call(this, event));
}
};
})($.ui.resizable.prototype["_mouseStart"]));
});
将其粘贴到您的javascript脚本部分.希望它可以帮助有类似问题的人!
Paste it in your javascript script section. Hope it helps someone with similar problem!
推荐答案
这对我有用,没有补丁
$('#resizable')
.resizable('option', 'aspectRatio', false)
.data('uiResizable')._aspectRatio = false;
这部分.data('uiResizable')._aspectRatio = false;
可以救助
这篇关于初始化后无法应用JqueryUI可调整大小的AspectRatio吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!