0

如何在设置https://github.com/trentrichardson/UberUploadCropper/blob/master/example-advanced/index.php中实时更改“aspectRatio”。

$(function() {

$.("#test1").click( function () {
    $ratio = 1;
});
$.("#test2").click( function () {
    $ratio = 2;
});

$('#UploadImages').uberuploadcropper({

...

'aspectRatio': $ratio, 

它不起作用。为什么?如何正确制作?

4

3 回答 3

0

定义一个全局变量$ratio

例子:

var $ratio; //Define a global variable like this
$(function() {

    $("#test1").click( function () {
        $ratio = 1;
        initPlugin();
    });
    $("#test2").click( function () {
        $ratio = 2;
        initPlugin();
    });

    function initPlugin() {    
        $('#UploadImages').uberuploadcropper({

             ...

             'aspectRatio': $ratio, //now the value will be taken from global scope
        });
    }
});
于 2012-05-02T20:58:36.100 回答
0

删除点$.("

$("#test1").click( function () {
    $ratio = 1;
});
$("#test2").click( function () {
    $ratio = 2;
});
于 2012-05-02T21:01:08.483 回答
0

您在设置变量之前调用插件。当点击事件触发时,您必须调用 .uberuploadcropper。尝试这样的事情:

$(function() {
    $.("#test1").click( function () {
        uploadCropper(1);
    });
    $.("#test2").click( function () {
        uploadCropper(2);
    });

    function uploadCropper(ratio){
        $('#UploadImages').uberuploadcropper({

            ...

            'aspectRatio': ratio, //now the value will be taken from global scope
        });
    }
});

于 2012-05-02T21:05:25.537 回答