fengyuanchen / cropperjs

JavaScript image cropper.
https://fengyuanchen.github.io/cropperjs/
MIT License
13.15k stars 2.42k forks source link

strange x value when call setData #1190

Closed zhouSir340 closed 3 months ago

zhouSir340 commented 3 months ago

Describe the bug using vue3 and encapsulate cropper into a component, calling setData after init, the response'x value is -1.8989449817236961e-13

To Reproduce Steps to reproduce the behavior:

  1. using vue3, using MyComponent, the image is base64 <MyComponent v-if="img" :image="img" style="width: 800px" />
  2. MyComponent will init cropper when mounted, and the options is like below:
    new Cropper(img.value, {
      background: false,
      guides: false,
      movable: false,
      viewMode: 2,
      dragMode: 'move',
      autoCropArea: 1,
      modal: false,
      scalable: false,
      zoomable: false,
      cropBoxMovable: false,
    });
    };
  3. calling setData func, the response is:
    {x: -1.8989449817236961e-13, 
    y: 0, 
    width: 2688, 
    height: 1520, 
    rotate: 0}
  4. Then I pulled the drag line on the left back and forth, call the setData, the response's x value is become normal 0

Expected behavior the x value of setData'response should be correct after init

Screenshots image

Desktop (please complete the following information):

Additional context

fengyuanchen commented 3 months ago

Only viewMode: 0 supports your case.