javascript - jQuery: cropit to remove image data and replace with a new one? -


i'm using cropit.js jquery plugin crop images in browser. plugin website here.

the issue have loading images dynamically based on image that's clicked on.

the first image loads fine , works perfectly. however, if click on second image or other image, doesn't load onto cropper area , first image gets stuck in cropping area reason.

i've tried create fiddle explain think due security reasons, external images wont load using cropit.js. also, jsfiddle wont allow http: url's couldn't fiddle , running. structure of code this: https://jsfiddle.net/hhshgeed/

you have run locally in simple html file images available in same folder html file. also, need include cropit.js well.

this entire code:

$('.position').live('click', function(){     var img = $(this).attr('src');     alert(img);      // re-enables cropper.     // opposite `disable` method.     $(function() {         $('.image-editor').cropit({             imagebackground: true,             imagebackgroundborderwidth: 20,             imagestate: {                 src: ''+img+'',             }          });           $('.rotate-cw').click(function() {              $('.image-editor').cropit('rotatecw');          });           $('.rotate-ccw').click(function() {               $('.image-editor').cropit('rotateccw');          });           $('.export').click(function() {              var imagedata = $('.image-editor').cropit('export', {                  type: 'image/webp',                  quality: .9,                  originalsize: true               });          });      }); }); 

as can see in code, i'm trying use variable img in cropit src function. works once.

imagestate: {     src: ''+img+'', } 

could please advise on issue i'm literally banging head against wall.

thanks in advance.

you need to destroy current instance of cropit using - $('.image-editor').cropit('destroy');


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -