Giter VIP home page Giter VIP logo

Comments (3)

galvesribeiro avatar galvesribeiro commented on May 14, 2024

Is there a way to set canvas to full document width and height?

You can set the width/height to whatever you want. Just set the properties on it.

Also can you retrieve the current canvas width and height in the component OnAfterRender()?

Today it doesn't support that as the ElementRef from Blazor doesn't allow you to invoke method/props on it.

from canvas.

Blightbuster avatar Blightbuster commented on May 14, 2024

You can scale the canvas with css:

canvas {
    background-color: #ffffff;
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
}

Its not perfect since you will have issues with unproportional scaling (a square on a 100x100 canvas may be displayed as a rectangle) as long as you dont know the aspect ratio of the canvas.

from canvas.

Blightbuster avatar Blightbuster commented on May 14, 2024

Ok so i tampered a bit and found a solution.
Put this into your css:

canvas {
    background-color: #ffffff;
    display: block;
    position: fixed;
}

And into your index.html you put this:

<script>
    function ResizeCanvas() {
        var canvas = document.querySelector('canvas');
        canvas.style.width = '100%';
        canvas.style.height = '100%';
        canvas.width = canvas.offsetWidth;
        canvas.height = canvas.offsetHeight;
        return { width: canvas.width, height: canvas.height };
    }
</script>

then call ResizeCanvas() with JSInterop either in the razor or in a cs file.

If you want to get the resulting size of the canvas you can use the return value of ResizeCanvas().

from canvas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.