jquery - Jcrop saves previous image -


i have preview cropping, , thumbnail displays part being cropped. whenever choose new image, preview not updated, instead keeps image being used previously. however, thumbnail updated, since shows new image. here code...

function readurl(input) {     if (input.files && input.files[0]) {         var reader = new filereader();          reader.onload = function (e) {             $('#previewsub2').attr('src', e.target.result);             $('#previewsub').attr('src', e.target.result);             ...             var imgwidth = $("#previewsub2").width();             var imgheight = $("#previewsub2").height();             $("#previewsub").jcrop({                 onchange: showpreview,                 onselect: showpreview,                 aspectratio: 1,                         setselect: [0,imgwidth,0,0],                 minsize: [90,90],                 addclass: 'jcrop-light'               });              ... 

previewsub2 thumbnail , previewsub jcrop image trying update. reason following code not updating it:

 $('#previewsub').attr('src', e.target.result); 

here rest of code showpreview:

function showpreview(coords) { var imgsize = $("#previewsub").height(); var imgwidth =  $("#previewsub").width();  var rx = 150 / coords.w; var ry = 150 / coords.h;  $('#x').val(); $('#y').val(); $('#w').val(); $('#h').val();  $('#previewsub2').css({     width: math.round(rx * imgwidth) + 'px',     height: math.round(ry * imgsize) + 'px',     marginleft: '-' + math.round(rx * coords.x) + 'px',     margintop: '-' + math.round(ry * coords.y) + 'px' }); } 

can explain me need update previewsub?

you can reload jcrop component this

var jcrop_api = null; function readurl(input) {     if (input.files && input.files[0]) {        var reader = new filereader();      reader.onload = function (e) {         if( jcrop_api ) {              jcrop_api.destroy();         }          $('#previewsub2').attr('src', e.target.result);         $('#previewsub').attr('src', e.target.result);         ...         var imgwidth = $("#previewsub2").width();         var imgheight = $("#previewsub2").height();          jcrop_api = $("#previewsub").jcrop({             onchange: showpreview,             onselect: showpreview,             aspectratio: 1,                     setselect: [0,imgwidth,0,0],             minsize: [90,90],             addclass: 'jcrop-light'           }); 

update: if you're using latest version of jcrop should set api such:

$("#previewsub").jcrop({     onchange: showpreview,     onselect: showpreview,     aspectratio: 1,             setselect: [0,imgwidth,0,0],     minsize: [90,90],     addclass: 'jcrop-light'      }, function() {         jcrop_api = this; }); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -