Jcrop not dragging
Jcrop not dragging
It uploads the image alright and highlights an area to be cropped but you can't drag the area and I have no idea why? Which bit does the drag or do I have some css missing? I presume it is possible to crop ore than one image on a page with more than one copy of the Jquery code with different field Ids? Thanks
- function updateInfo(e) {
- $('#x1').val(e.x);
- $('#y1').val(e.y);
- $('#x2').val(e.x2);
- $('#y2').val(e.y2);
- $('#w').val(e.w);
- $('#h').val(e.h);
- };
-
- // clear info by cropping (onRelease event handler)
- function clearInfo() {
- $('#w').val('');
- $('#h').val('');
- };
-
- // Create variables (in this scope) to hold the Jcrop API and image size
- var jcrop_api, boundx, boundy;
-
- function fileSelectHandler1() {
- // get selected file
- var oFile = $('#browse_file1')[0].files[0];
- // hide all errors
- $('.error').hide();
- // check for image type (jpg and png are allowed)
- var rFilter = /^(image\/jpeg|image\/png)$/i;
- if (! rFilter.test(oFile.type)) {
- $('.error').html('Please select a valid image file (jpg and png are allowed)').show();
- return;
- }
- // check for file size
- if (oFile.size > 250 * 1024) {
- $('.error').html('You have selected too big file, please select a one smaller image file').show();
- return;
- }
- // preview element
- var oImage = document.getElementById('image1');
- // prepare HTML5 FileReader
- var oReader = new FileReader();
- oReader.onload = function(e) {
-
- // e.target.result contains the DataURL which we can use as a source of the image
- oImage.src = e.target.result;
- oImage.onload = function () { // onload event handler
- // display step 2
- $('.step2').fadeIn(500);
- // destroy Jcrop if it is existed
- if (typeof jcrop_api != 'undefined') {
- jcrop_api.destroy();
- jcrop_api = null;
- $('#image1').width(oImage.naturalWidth);
- $('#image1').height(oImage.naturalHeight);
- }
- setTimeout(function(){
- // initialize Jcrop
- $('#image1').Jcrop({
- minSize: [32, 32], // min crop size
- aspectRatio : 1, // keep aspect ratio 1:1
- bgFade: true, // use fade effect
- bgOpacity: .3, // fade opacity
- onChange: updateInfo,
- onSelect: updateInfo,
- onRelease: clearInfo
- }, function(){
- // use the Jcrop API to get the real image size
- var bounds = this.getBounds();
- boundx = bounds[0];
- boundy = bounds[1];
- // Store the Jcrop API in the jcrop_api variable
- jcrop_api = this;
- });
- },3000);
- };
- };
-
- // read selected file as DataURL
- oReader.readAsDataURL(oFile);
- }