Paper.js won't resize the canvas correctly

后端 未结 3 592
忘掉有多难
忘掉有多难 2021-02-02 08:29

I\'m trying out Paper.js for fun, but it seems I\'m already stuck at the very start.

Adding resize=\"true\" to the canvas tag is supposed to ma

相关标签:
3条回答
  • 2021-02-02 09:08

    Add the following CSS to your project:

    <style type="text/css">
    html,
    body {
        margin: 0;
        overflow: hidden;
        height: 100%;
    }
    
    /* Scale canvas with resize attribute to full size */
    canvas[resize] {
        width: 100%;
        height: 100%;
    }
    </style>
    
    0 讨论(0)
  • 2021-02-02 09:18

    I opened an issue for this on Github and it seems that this is a bug introduced in 0.9.22. @Skalkaz pointed me this question.

    Here is the pending issue: https://github.com/paperjs/paper.js/issues/662.

    You can also downgrade to 0.9.21 while waiting for a patch.

    0 讨论(0)
  • 2021-02-02 09:19

    Another option is - if you are using set proportions (relative to the body) - to override paper's view:

    var pageWidth = document.getElementsByTagName("BODY")[0].clientWidth
    var pageHeight = document.getElementsByTagName("BODY")[0].clientHeight
    view.size.width = pageWidth * myWidthScale
    view.size.height = pageHeight * myHeightScale
    center = new Point(width / 2, pageHeight / 2)
    view.center = center
    
    0 讨论(0)
提交回复
热议问题