May 2, 2012
jQuery change var by event in real time – not work
Question by Михаил Дмитриев
How make change “aspectRatio” in settings https://github.com/trentrichardson/UberUploadCropper/blob/master/example-advanced/index.php in real time.
$(function() {
$.("#test1").click( function () {
$ratio = 1;
});
$.("#test2").click( function () {
$ratio = 2;
});
$('#UploadImages').uberuploadcropper({
...
'aspectRatio': $ratio,
It not work. Why?
How it is correct to make?
Answer by Starx
Define a global variable of the $ratio
.
Example:
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
});
}
});