Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Inline CSS style tag prevents canvas from responsively resizing #256

Open
@evadecker

Description

Been using OGL for a bit to create shaders. Nice library, thank you!

Problem:

The Renderer logic currently adds width and height on canvas in addition to an inline style tag:

Image

Because of these inline styles, it isn't possible to make the canvas element responsive based on its own clientWidth. The canvas will be set up with default styles but will not reflow on resize.

canvas {
 width: 100%;
}
// Will not work! The inline styles prevent `clientWidth` from updating.
// On first load, the canvas will be appropriately sized at 100%, but
// the element won't reflow or change sizes along with the rest of the DOM.
function updateCanvasSize() {
 const { clientWidth, clientHeight } = canvas;
 renderer.setSize(clientWidth, clientHeight);
}
render() {
 // ...
 updateCanvasSize();
}

Fix:

Do not set inline style on canvas. Allow users to update the canvas size during the render loop as illustrated in this example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /