August 2017
Beginner
298 pages
7h 4m
English
If the user selects a large image (for example, an image the size of the screen), it will cause the layout to break. To prevent this from happening, we need to zoom out our canvas when large images are selected. We can zoom in or zoom out our canvas element by controlling its height and width in CSS. In the Memes class, create the following function:
resizeCanvas(canvasHeight, canvasWidth) { let height = canvasHeight; let width = canvasWidth; this.$canvas.style.height = `${height}px`; this.$canvas.style.width = `${width}px`; while(height > Math.min(1000, deviceWidth-30) && width > Math.min(1000, deviceWidth-30)) { height /= 2; width /= 2; this.$canvas.style.height = `${height}px`; this.$canvas.style.width ...Read now
Unlock full access