未验证 提交 819c8523 编写于 作者: O openharmony_ci 提交者: Gitee

!11340 canvas js文档整改

Merge pull request !11340 from lanyi/pr_11283
...@@ -25,19 +25,21 @@ addColorStop(offset: number, color: string): void ...@@ -25,19 +25,21 @@ addColorStop(offset: number, color: string): void
<!-- xxx.hml --> <!-- xxx.hml -->
<div> <div>
<canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas> <canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas>
<input type="button" style="width: 180px; height: 60px;" value="fillStyle"onclick="handleClick" />
</div> </div>
``` ```
```js ```js
// xxx.js // xxx.js
export default { export default {
handleClick() { onShow() {
const el =this.$refs.canvas; const el =this.$refs.canvas;
const ctx =el.getContext('2d'); const ctx = el.getContext('2d');
const gradient = ctx.createLinearGradient(0,0,100,0); const gradient = ctx.createLinearGradient(50,0,300,100);
gradient.addColorStop(0,'#00ffff'); gradient.addColorStop(0.0, 'red')
gradient.addColorStop(1,'#ffff00'); gradient.addColorStop(0.5, 'white')
gradient.addColorStop(1.0, 'green')
ctx.fillStyle = gradient
ctx.fillRect(0, 0, 300, 300)
} }
} }
``` ```
......
...@@ -584,7 +584,7 @@ fillRect(x: number, y: number, width:number, height: number): void ...@@ -584,7 +584,7 @@ fillRect(x: number, y: number, width:number, height: number): void
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div> <div>
<canvas ref="canvas" style="width: 200px; height: 150px; "></canvas> <canvas ref="canvas" style="width: 500px; height: 500px; "></canvas>
</div> </div>
``` ```
...@@ -620,7 +620,7 @@ clearRect(x: number, y: number, width:number, height: number): void ...@@ -620,7 +620,7 @@ clearRect(x: number, y: number, width:number, height: number): void
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div> <div>
<canvas ref="canvas" style="width: 200px; height: 150px;"></canvas> <canvas ref="canvas" style="width: 500px; height: 500px;"></canvas>
</div> </div>
``` ```
...@@ -983,7 +983,7 @@ createPattern(image: Image, repetition: string): Object ...@@ -983,7 +983,7 @@ createPattern(image: Image, repetition: string): Object
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div> <div>
<canvas ref="canvas" style="width: 200px; height: 150px;"></canvas> <canvas ref="canvas" style="width: 1000px; height: 1000px;"></canvas>
</div> </div>
``` ```
...@@ -997,7 +997,7 @@ createPattern(image: Image, repetition: string): Object ...@@ -997,7 +997,7 @@ createPattern(image: Image, repetition: string): Object
img.src = 'common/images/example.jpg'; img.src = 'common/images/example.jpg';
var pat = ctx.createPattern(img, 'repeat'); var pat = ctx.createPattern(img, 'repeat');
ctx.fillStyle = pat; ctx.fillStyle = pat;
ctx.fillRect(0, 0, 20, 20); ctx.fillRect(0, 0, 500, 500);
} }
} }
``` ```
...@@ -1573,7 +1573,7 @@ drawImage(image: Image | PixelMap, sx: number, sy: number, sWidth: number, sHeig ...@@ -1573,7 +1573,7 @@ drawImage(image: Image | PixelMap, sx: number, sy: number, sWidth: number, sHeig
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div> <div>
<canvas style="width: 200px; height: 150px; background-color: #ffff00;"></canvas> <canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas>
</div> </div>
``` ```
...@@ -1581,11 +1581,11 @@ drawImage(image: Image | PixelMap, sx: number, sy: number, sWidth: number, sHeig ...@@ -1581,11 +1581,11 @@ drawImage(image: Image | PixelMap, sx: number, sy: number, sWidth: number, sHeig
//xxx.js //xxx.js
export default { export default {
onShow() { onShow() {
var test = this.$element('drawImage'); var test = this.$refs.canvas;
var ctx = test.getContext('2d'); var ctx = test.getContext('2d');
var img = new Image(); var img = new Image();
img.src = 'common/image/test.jpg'; img.src = 'common/image/test.jpg';
ctx.drawImage(img, 50, 80, 80, 80); ctx.drawImage(img, 0, 0, 200, 200, 10, 10, 200, 200);
} }
} }
``` ```
......
...@@ -65,7 +65,7 @@ setTransform(scaleX: number, skewX: number, skewY: number, scaleY: number, trans ...@@ -65,7 +65,7 @@ setTransform(scaleX: number, skewX: number, skewY: number, scaleY: number, trans
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div> <div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas> <canvas ref="canvas" style="width: 300px; height: 250px; background-color: #ffff00;"></canvas>
</div> </div>
``` ```
...@@ -96,7 +96,7 @@ closePath(): void ...@@ -96,7 +96,7 @@ closePath(): void
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div> <div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas> <canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas>
</div> </div>
``` ```
...@@ -224,7 +224,7 @@ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, ...@@ -224,7 +224,7 @@ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number,
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div> <div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas> <canvas ref="canvas" style="width: 300px; height: 250px; background-color: #ffff00;"></canvas>
</div> </div>
``` ```
...@@ -265,7 +265,7 @@ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void ...@@ -265,7 +265,7 @@ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div> <div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas> <canvas ref="canvas" style="width: 300px; height: 250px; background-color: #ffff00;"></canvas>
</div> </div>
``` ```
...@@ -308,7 +308,7 @@ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, ...@@ -308,7 +308,7 @@ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number,
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div> <div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas> <canvas ref="canvas" style="width: 300px; height: 250px; background-color: #ffff00;"></canvas>
</div> </div>
``` ```
...@@ -349,7 +349,7 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void ...@@ -349,7 +349,7 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div> <div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas> <canvas ref="canvas" style="width: 300px; height: 250px; background-color: #ffff00;"></canvas>
</div> </div>
``` ```
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
**示例:** **示例:**
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div style="width: 180px; height: 60px;"> <div style="width: 500px; height: 500px;">
<canvas ref="canvasId" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas> <canvas ref="canvasId" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas>
</div> </div>
``` ```
...@@ -94,7 +94,7 @@ isPointInPath(path?: Path2D, x: number, y: number): boolean ...@@ -94,7 +94,7 @@ isPointInPath(path?: Path2D, x: number, y: number): boolean
**示例:** **示例:**
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div style="width: 180px; height: 60px;"> <div style="width: 500px; height: 500px;">
<text>In path:{{textValue}}</text> <text>In path:{{textValue}}</text>
<canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas> <canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas>
</div> </div>
...@@ -144,7 +144,7 @@ isPointInStroke(path?: Path2D, x: number, y: number): boolean ...@@ -144,7 +144,7 @@ isPointInStroke(path?: Path2D, x: number, y: number): boolean
**示例:** **示例:**
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div style="width: 180px; height: 60px;"> <div style="width: 500px; height: 500px;">
<text>In path:{{textValue}}</text> <text>In path:{{textValue}}</text>
<canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas> <canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas>
</div> </div>
...@@ -180,7 +180,7 @@ resetTransform(): void ...@@ -180,7 +180,7 @@ resetTransform(): void
**示例:** **示例:**
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div style="width: 180px; height: 60px;"> <div style="width: 500px; height: 500px;">
<text>In path:{{textValue}}</text> <text>In path:{{textValue}}</text>
<canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas> <canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas>
</div> </div>
......
...@@ -1745,7 +1745,7 @@ rotate(angle: number): void ...@@ -1745,7 +1745,7 @@ rotate(angle: number): void
.height('100%') .height('100%')
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() =>{ .onReady(() =>{
this.context.rotate(45 * Math.PI / 180) // Rotate the rectangle 45 degrees this.context.rotate(45 * Math.PI / 180)
this.context.fillRect(70, 20, 50, 50) this.context.fillRect(70, 20, 50, 50)
}) })
} }
......
...@@ -1850,7 +1850,7 @@ rotate(angle: number): void ...@@ -1850,7 +1850,7 @@ rotate(angle: number): void
.height('100%') .height('100%')
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() =>{ .onReady(() =>{
this.offContext.rotate(45 * Math.PI / 180) // Rotate the rectangle 45 degrees this.offContext.rotate(45 * Math.PI / 180)
this.offContext.fillRect(70, 20, 50, 50) this.offContext.fillRect(70, 20, 50, 50)
var image = this.offContext.transferToImageBitmap() var image = this.offContext.transferToImageBitmap()
this.context.transferFromImageBitmap(image) this.context.transferFromImageBitmap(image)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册