Unable to apply JqueryUI Resizable AspectRatio after initialization?

百般思念 提交于 2019-12-03 12:02:41

This worked for me with no patching

$('#resizable')
  .resizable('option', 'aspectRatio', false)
  .data('uiResizable')._aspectRatio = false;

This part .data('uiResizable')._aspectRatio = false; comes to the rescue

I don't know if it will work or what will happen. But you can try something like this.

$(function(){
    var settings = {
        aspectRatio : .75  
    };
    $("#tadaa").resizable(settings);

    $("input").change(function(){
        if($(this).is(":checked"))
        {

            $("#tadaa").resizable( "destroy" );
            $("#tadaa").resizable();
        }
        else  
        {
            $("#tadaa").resizable( "destroy" );
            $("#tadaa").resizable(settings);
        }   
    });
});

Live demo, currently only the bottom draggable element is styled to use, horizontal div is not styled.

http://jsfiddle.net/t6xFN/1/

I realize that this is an old post but in case anyone still needs an answer you can do it like this:

$('#aspect_check').click( function() {
    var ischecked = $('#aspect_check').prop('checked');
    if (ischecked) {
        $( "#resizable" ).resizable({aspectRatio : .75});
    } else {
        $( "#resizable" ).resizable();
    }
});

Another solution is to save resizable options in a variable and destroy and reinitialize the widget with the updated options:

var options = $("#resizable").resizable("options");
if (ischecked) {
    options.aspectRatio = .75;
} else {
    options.aspectRatio = false;
}
$("#resizable").resizable("destroy");
$("#resizable").resizable(options);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!