Canvasfillrect solves the problem that the height of the canvas is doubled when fillRect () is used.

Source: Internet
Author: User

Canvasfillrect solves the problem that the height of the canvas is doubled when fillRect () is used.

When you set the width and height of the canvas, only built-in css is valid. external css is stretched, for example:

<! DOCTYPE html> 

The information is as follows:

This effect is different from what we expected. There are two ways to modify it:

(1)Add the code setting width and height attribute in code js to set the width and height:

canvas.setAttribute("height",canvas.clientHeight);canvas.setAttribute("width",canvas.clientWidth);

(2)In addition to the Code for setting the width and height attributes in external css, add the width and height attributes to the canvas label directly:

<Canvas id = "canvas" width = "300" height = "400"> <span> canvas labels are not supported </span> </canvas>

The final result is as follows:

The above article solves the problem of double effect in height when using fillRect () on the canvas. This is all the content that I have shared with you. I hope you can give us a reference and support for the help house.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.