当前位置:网站首页>Chapter 1 overview of canvas
Chapter 1 overview of canvas
2022-06-24 07:58:00 【yxqq378287007】
《canvas》 The first 1 Chapter canvas summary
The first 1 Chapter canvas summary
1.1 canvas What is it?
1.1.1 canvas brief introduction
canvas( canvas ),html5 in ,canvas Element combination JavaScript Draw all kinds of figures .
- Drawing graphics ( rectangular 、 curve 、 Circle, etc. )
- Charting
- Animation effect
- Game development
1.1.2 canvas And SVG
- canvas Use JavaScript Dynamic generation ,SVG Use XML Static description .
- canvas Based on bitmaps , Suitable for pixel and dynamic rendering , Amplification will distort ;SVG Based on vector , Applicable static description , Amplification doesn't distort .
- Changes have taken place ,canvas Need to redraw ,SVG Unwanted .
- Similar to the relationship between art and geometry .
1.2 canvas Elements
htaml5 Use in canvas Element drawing three steps :
- obtain canvas object .
- Get context object context.
- Start drawing graphics .
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8"/>
<script type="text/javascript"> window.onload = function () {
//1、 obtain canvas object var cnv = document.getElementById("canvas"); //2、 Get context object context var cxt = cnv.getContext("2d"); //3、 Start drawing graphics cxt.moveTo(50, 100); cxt.lineTo(150, 50); cxt.stroke(); } </script>
</head>
<body>
<canvas id="canvas" width="200" height="150" style="border:1px dashed gray;"></canvas>
</body>
</html>
1.2.1 canvas Introduction to elements
Inline block element (inline-block), Generally, you need to specify 3 Attributes ,id、width( Default 300px) and height( Default 150px).
In development ,width and height belong HTML Property definition , Not in CSS The style defines .
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8"/>
<style type="text/css"> canvas {
width: 200px; height: 150px; } </style>
<script type="text/javascript"> window.onload = function () {
var cnv = document.getElementById("canvas"); var str = "canvas The width is :" + cnv.width + ", The height is :" + cnv.height; alert(str); // Can't get CSS in width and height, Use the default value 300,150. } </script>
</head>
<body>
<canvas id="canvas" style="border:1px dashed gray;"></canvas>
</body>
</html>
1.2.2 canvas object
- Common properties
width、height - Common methods
getContext(“2d”), obtain Canvas 2D Context object (context object )
toDataURL(), obtain canvas Object to generate a string of bitmaps
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta charset="utf-8"/>
<script type="text/javascript"> window.onload = function () {
var cnv = document.getElementById("canvas"); var str = "Canvas The width is :" + cnv.width + ", The height is :" + cnv.height; alert(str); } </script>
</head>
<body>
<canvas id="canvas" width="200" height="160" style="border:1px dashed gray"></canvas>
</body>
</html>
To reassure
- html5 canvas For the time being, only 2D mapping API,3D Drawing use html5 in WebGL Realization .
- IE9 And above support html5 canvas,IE7 And IE8 Compatibility through explorercanvas Extended solution , There will be many functional limitations , None unavailable fillText() Such method .
<!--[if IE]> <script src="https://github.com/arv/explorercanvas/excanvas.js"></script> <![end if]-->
- recommend canvas course .
W3C Official website :www.w3.org/TR/2dcontext/
边栏推荐
- These dependencies were not found: * core JS / modules / es6 array. Fill in XXX
- L1-019 谁先倒 (15 分)
- Any remarks
- Thread blocking
- Moonwell Artemis is now online moonbeam network
- ImportError: cannot import name ‘process_ pdf‘ from ‘pdfminer. Pdfinterp 'error completely resolved
- 10. Tencent cloud IOT device side learning - firmware upgrade
- 交友相亲类软件是如何割你韭菜的
- OpenGauss数据库在 CentOS 上的实践,配置篇
- 用Ngrok 配置属于自己的免费外网域名
猜你喜欢

Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of its

Chapter 3: drawing triangles

Moonwell Artemis现已上线Moonbeam Network

Open cooperation and win-win future | Fuxin Kunpeng joins Jinlan organization

Part 2: drawing a window

从 jsonpath 和 xpath 到 SPL

What kind of experience is it when the Institute earns 20000 yuan a month!

Signature analysis of app x-zse-96 in a Q & a community

Keep one decimal place and two decimal places

Mousse shares listed on Shenzhen Stock Exchange: gross profit margin continued to decline, and marketing failed in the first quarter of 2022
随机推荐
10. Tencent cloud IOT device side learning - firmware upgrade
力扣(LeetCode)174. 地下城游戏(2022.06.23)
屏幕截图推荐—Snipaste
Bit operation
duilib 显示内存图片
Hongmeng development IV
Random number remarks
Standing at the center of the storm: how to change the engine of Tencent
洛谷 P1051 谁拿了最多奖学金
Q & A on cloud development cloudbase hot issues of "Huage youyue phase I"
BOM笔记
The describeregion interface of CVM is special and has two versions
智能指针备注
Thread blocking
Timer usage notes
tuple(元组)备注
《canvas》之第3章 曲线图形
鸿蒙开发四
IndexError: Target 7 is out of bounds.
日期、时间库使用备注