-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Canvas Resize #6
Comments
I do this, it's not beatiful but it works for me: canvasWidth = if canvas.offsetWidth != 0 then canvas.offsetWidth else $('.canvas-container').width() # I use the width of the div which contains the canvas
canvasHeight = if canvas.offsetHeight != 0 then canvas.offsetHeight else 116 # I hardcode this because my signature must always have the same height.
canvas.width = canvasWidth * ratio
canvas.height = canvasHeight * ratio |
Any chance you could update your main repo with how to make the canvas responsive? The comment above makes no sense to me. I'm reluctant to do Javascript when a pure AngularJS solution should work. No matter what size I set the CSS of the Canvas, it always stretches it without redrawing the available area. |
Don't forget that when defining the size of a canvas element, there are two sizes, html and css. You have to define the html size of the canvas. By the way, I improved my solution. It has some js, btw, maybe you don't like it... ratio = window.devicePixelRatio || 1
canvasWidth = if canvas.offsetWidth != 0 then canvas.offsetWidth else $('.canvas-container').width()
aspectRatio = 2.5 # Just because I want this ratio
canvasHeight = canvas.offsetWidth / aspectRatio
$('.canvas-container').css('height', "#{$('.canvas-container').width() / aspectRatio}px")
canvas.width = canvasWidth * ratio
canvas.height = canvas.width / aspectRatio
canvas.getContext("2d").scale(ratio, ratio)
# Some code to load the content of the canvas again |
Thanks so much for this angular version. Any idea on how to get this portion to work?
The text was updated successfully, but these errors were encountered: