websanova / wPaint

jQuery Paint Plugin
http://wpaint.websanova.com
351 stars 128 forks source link

Resizing Canvas #123

Open pallavidhanopiya opened 6 years ago

pallavidhanopiya commented 6 years ago

Hello, I'm trying to resize my canvas on change of device orientation in mobile web view. I'm using the below code: $(window).resize(function () { $('#wPaint_181_17').css({ width: $(window).width(), height: $(window).height()
}); });

In my canvas area i have any image and I draw something on it, it's working fine. I change orientation of device and call method to resize canvas, it works image is resized. But now when i'm using any canvas tool to draw on image , then the coordinates are shifting. If i'm drawing on left area then it's viewed shifted towards more right.

If I reload my page then it works fine, but I can't reload the page because I have some other data entered by user on the page and also previous changes done in Canvas image which I need to store on change of device orientation. Please suggest some solution.

JulyanoF commented 5 years ago

My solution was this:

$(window).on('resize', function(){
    setTimeout(() => {
      if($('#wPaint').length){
        $("#wPaint").wPaint('resize');
      }
    }, 350);
  });