如何实时更改设置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,
不起作用。为什么? 怎么做是正确的?
答案 0 :(得分: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
});
}
});
答案 1 :(得分:0)
在$.("
$("#test1").click( function () {
$ratio = 1;
});
$("#test2").click( function () {
$ratio = 2;
});
答案 2 :(得分:0)
您在设置变量之前调用插件。触发click事件时,必须调用.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
});
}
});