Problem with Responsive Layout
Everything is OK when the canvas have precise size. When I tried to add lines with Responsiveness, animation is not visible.
In the Editor everything works, what a pity that we can’t see it via share link: https://rive.app/s/aZaQ99KBOkyjayI4loJRIQ/?runtime=rive-renderer
Here’s the code:
<canvas id="riveCanvas"></canvas>
<script src="https://unpkg.com/@rive-app/canvas"></script>
<script>
const rive = new rive.Rive({
src: "https://grzegorzsamson.pl/wp-content/uploads/2026/01/gs_timeline.riv",
canvas: riveCanvas,
layout: new Layout({
fit: Fit.Layout,
// layoutScaleFactor: 2, // 2x scale of the layout, when using `Fit.Layout`. This allows you to resize the layout as needed.
}),
autoplay: true,
// artboard: "Arboard", // Optional. If not supplied the default is selected
stateMachines: "State Machine 1",
autoBind: true,
onLoad: () => {
// Ensure the drawing surface matches the canvas size and device pixel ratio
let boundInstance = rive.viewModelInstance;
computeSize();
},
});
function computeSize() {
rive.resizeDrawingSurfaceToCanvas();
}
// Subscribe to window size changes and update call `resizeDrawingSurfaceToCanvas`
window.onresize = computeSize;
// Subscribe to devicePixelRatio changes and call `resizeDrawingSurfaceToCanvas`
window
.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`)
.addEventListener("change", computeSize);
</script>