onViewportResize
API reference for the "onViewportResize" method.
This callback is superseded by the onLayoutChange callback and the TypeScript definitions no longer exist in the @canva/editing-extensions-api-typings package.
Registers a callback that runs when:
  • The user resizes the iframe that contains their image.
  • The user changes the zoom level of the document.

Usage

1
const canva = window.canva.init();
2
3
canva.onReady(async (opts) => {
4
// This method must exist for the extension to start
5
});
6
7
canva.onViewportResize(async (opts) => {
8
console.log(opts);
9
});
Copied!

Parameters

Name
Type
Required
Description
handler
Yes
The callback to run when the size of the viewport changes.

Returns

void

Types

ViewportResizeHandler

The callback to run when the size of the viewport changes.
Signature
1
(opts) => void
Copied!
Parameters
Name
Type
Required
Description
opts
object
Yes
Information about the event.
opts.commit
boolean
Yes
If false, the user is resizing the viewport. If true, the user has finished resizing the viewport.
opts.size
object
Yes
The dimensions of the viewport.
opts.size.height
number
Yes
The height of the viewport, in pixels.
opts.size.width
number
Yes
The width of the viewport, in pixels.
Returns
void