-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jinfeiyang
committed
Mar 17, 2021
1 parent
9656453
commit f63260f
Showing
5 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<script src="https://cdn.jsdelivr.net/npm/eruda"></script> | ||
<script>eruda.init();</script> | ||
<style> | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body style="background:#fff;"> | ||
<canvas id="canvas" style="width:100%; height:100%; position:fixed;"></canvas> | ||
|
||
<script src="../dist/easy-canvas.min.js"></script> | ||
<script src="./draw.js"></script> | ||
<script> | ||
window.onload = function () { | ||
main() | ||
|
||
} | ||
window.onresize = function () { | ||
main() | ||
} | ||
|
||
function main() { | ||
const canvas = document.querySelector('#canvas') | ||
|
||
const ctx = canvas.getContext('2d') | ||
const dpr = window.devicePixelRatio | ||
const w = window.innerWidth | ||
const h = window.innerHeight | ||
canvas.width = w * dpr | ||
canvas.height = h * dpr | ||
ctx.scale(dpr, dpr) | ||
layer = easyCanvas.createLayer(ctx, { dpr, width: w, height: h }) | ||
|
||
const node = easyCanvas.createElement((h) => { | ||
return h('view', { styles: { backgroundColor: '#fff' } }, [ | ||
this.drawTicket(h), | ||
h('view',{ | ||
styles:{ | ||
height:100, | ||
padding:10 | ||
}, | ||
render(ctx,canvas,target){ | ||
const {x,y} = target | ||
console.log(target) | ||
const {contentWidth,contentHeight} = target.renderStyles | ||
ctx.beginPath() | ||
ctx.quadraticCurveTo(x+10,y+30,x+100,y+50) | ||
ctx.quadraticCurveTo(x+10,y+30,x+100,y+100) | ||
ctx.closePath() | ||
ctx.stroke() | ||
} | ||
},[ | ||
h('text',{},'自定义render,支持操作ctx绘制,并且可以获取到布局信息。') | ||
]) | ||
]) | ||
}) | ||
node.mount(layer) | ||
console.log(node) | ||
} | ||
|
||
// 注册全局组件 | ||
canvas.ontouchstart = ontouchstart | ||
canvas.ontouchmove = ontouchmove | ||
canvas.ontouchend = ontouchend | ||
canvas.onmousedown = ontouchstart | ||
canvas.onmousemove = ontouchmove | ||
canvas.onmouseup = ontouchend | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters