popcodeorg / popcodeorg/popcode
validation on canvas element incorrectly flags 'width' attribute as an error
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 191
- Fork
- 143
- Merge trung bình
- 4 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 5
Mô tả
I'm trying to use a <canvas> element (for a Tiny Turtle exercise) and set its width to something larger than the default of 300px. Naively I tried a css rule:
canvas {
width: 100%;
min-height: 400px;
}
But with <canvas>, a css-specified width actually scales the content. This makes the turtle head and line segments appear quite large and even pixellated and does not actually give any more room to draw.
MDN recommends instead that you set the width and height directly on the element. Trying this triggered a popcode validation error on width:
9
Don't use the "width" attribute. Instead, use the CSS width property
Impact: mostly a little annoying. You can't set the real width of the canvas, so there will be unused space at the right margin -- and quite noticeable with a bigger screen. Complicated turtle drawings may not fit well into 300x150 px (although for some reason the height attribute is allowed through validation, so the canvas can be made taller).
Also, the validator-recommended fix isn't a real fix, which is minor in and of itself but we'd like users to be able to rely on its recommendations.
Steps to reproduce:
- Open this popcode link: https://popcode.org/?gist=1791db30a9fa1cbcc39e0ec181388634
- In the html panel, set the
<canvas>element's width attribute to, say, 400. Observe the validation error. - Observe the somewhat-pixellated turtle stamp render (due to the css width being set w/o html width).
- Observe the rendered length of a
forward(30)segment. Cut thatforwarddown to 10 units to allow more drawing room. Observe that the stamp now overwhelms the line segment.
On a page without validation, eg jsbin, setting the width attr has the desired result of setting the canvas's coordinate system width (which can then optionally be scaled with css).
Tested on macos 10.11 with Safari 10.0.3 and Chrome 56.0.2924.87.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện lỗi xác thực bằng gist Popcode được liên kết, tập trung vào một phần tử canvas có thuộc tính width và thông báo của validator đề xuất CSS width. Truy vết điểm bắt đầu của validator phát ra thông báo này và so sánh cách xử lý width với height. Công việc được hoàn tất khi một width hợp lệ của canvas được chấp nhận và đề xuất đó không còn mâu thuẫn với hành vi định kích thước của canvas.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- html, javascript
- Lĩnh vực
- frontend, testing-qa, web-dev
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 38/100