Search
Loading...
Skip to content

Move Videos

Position videos on the canvas using absolute pixel coordinates or percentage-based positioning for responsive layouts.

Move videos example showing positioned videos with labels

8 mins
estimated time
Download
StackBlitz
GitHub

Position videos on the canvas using coordinates that start at the top-left corner (0, 0). X increases right, Y increases down. Values are relative to the parent block, simplifying nested layouts.

This guide covers positioning videos with absolute or percentage coordinates, configuring position modes, and locking transforms to prevent repositioning.

Position Coordinates#

Coordinates originate at the top-left (0, 0) of the parent container. Use absolute mode for fixed pixel values or percentage mode (0.0 to 1.0) for responsive layouts that adapt to parent size changes.

Positioning Videos#

Position videos using engine.block.setPositionX() and engine.block.setPositionY() with absolute pixel coordinates:

engine.block.appendChild(page, movableVideo);
engine.block.setPositionX(movableVideo, 0);
engine.block.setPositionY(movableVideo, 100);

Getting Current Position#

Read current position values using engine.block.getPositionX() and engine.block.getPositionY(). Values are returned in the current position mode (absolute pixels or percentage 0.0-1.0):

// Get current position values
const currentX = engine.block.getPositionX(movableVideo);
const currentY = engine.block.getPositionY(movableVideo);

Configuring Position Modes#

Control how position values are interpreted using engine.block.setPositionXMode() and engine.block.setPositionYMode(). Set to 'Absolute' for pixels or 'Percent' for percentage values (0.0 to 1.0). Check the current mode using engine.block.getPositionXMode() and engine.block.getPositionYMode(). The Percentage Positioning section below demonstrates setting these modes.

Percentage Positioning#

Position videos using percentage values (0.0 to 1.0) for responsive layouts. Set the position mode to 'Percent', then use values between 0.0 and 1.0:

// Set position mode to percentage (0.0 to 1.0)
engine.block.setPositionXMode(percentVideo, 'Percent');
engine.block.setPositionYMode(percentVideo, 'Percent');

Percentage positioning adapts automatically when the parent block dimensions change, maintaining relative positions in responsive designs.

Relative Positioning#

Move videos relative to their current position by getting the current coordinates and adding offset values:

// Move relative to current position
const offsetX = engine.block.getPositionX(movableVideo);
const offsetY = engine.block.getPositionY(movableVideo);
engine.block.setPositionX(movableVideo, offsetX + 50);
engine.block.setPositionY(movableVideo, offsetY + 50);

Locking Transforms#

Lock transforms to prevent repositioning, rotation, and scaling by setting transformLocked to true:

// Lock the transform to prevent user interaction
engine.block.setBool(lockedVideo, 'transformLocked', true);

Troubleshooting#

Video Not Moving#

Check if transforms are locked using engine.block.getBool(block, 'transformLocked'). Ensure the video block exists and values are within parent bounds.

Unexpected Position Values#

Check position mode using engine.block.getPositionXMode() and engine.block.getPositionYMode(). Verify if using absolute (pixels) vs percentage (0.0-1.0) values. Review parent block dimensions if using percentage positioning.

Positioned Outside Visible Area#

Verify parent block dimensions and boundaries. Check coordinate system: origin is top-left, not center. Review X/Y values for calculation errors.

Percentage Positioning Not Responsive#

Ensure position mode is set to 'Percent' using engine.block.setPositionXMode(block, 'Percent'). Verify percentage values are between 0.0 and 1.0. Check that parent block dimensions can change.

API Reference#

MethodDescription
engine.block.addVideo()Create and position video in one operation
engine.block.setPositionX()Set X coordinate value
engine.block.setPositionY()Set Y coordinate value
engine.block.getPositionX()Get current X coordinate value
engine.block.getPositionY()Get current Y coordinate value
engine.block.setPositionXMode()Set position mode for X coordinate
engine.block.setPositionYMode()Set position mode for Y coordinate
engine.block.getPositionXMode()Get position mode for X coordinate
engine.block.getPositionYMode()Get position mode for Y coordinate
engine.block.setBool()Set transform lock state
engine.block.getBool()Get transform lock state