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

const canva = window.canva.init();
canva.onReady(async (opts) => {
// This method must exist for the extension to start
});
canva.onViewportResize(async (opts) => {
console.log(opts);
});

Parameters

Name

Type

Required

Description

handler

ViewportResizeHandler

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

(opts) => void

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