当前位置:网站首页>[wechat applet development (native)] canvas animation
[wechat applet development (native)] canvas animation
2022-07-24 08:15:00 【Sock is a dog】
<!-- canvas.wxml -->
<canvas type="2d" id="myCanvas"></canvas>
// canvas.js
Page({
onReady() {
const query = wx.createSelectorQuery()
query.select('#myCanvas')
.fields({
node: true, size: true })
.exec((res) => {
const canvas = res[0].node
const ctx = canvas.getContext('2d')
const dpr = wx.getSystemInfoSync().pixelRatio
canvas.width = res[0].width * dpr
canvas.height = res[0].height * dpr
ctx.scale(dpr, dpr)
ctx.fillRect(0, 0, 100, 100)
})
}
})
The above is official canvas demo
among if necessary drawImage, Load pictures under the project directory ,
JavaScript Of canvas It's written like this
var image = new Image();
image.src="/images/head.jpeg";
image.onload=function(){
ctx.drawImage(this,0,0,60,60,0,0,120,120);
}
If this is written in the applet, an error will be reported No definition Image
It needs this
var img = canvas.createImage();
image.src="/images/head.jpeg";
image.onload=function(){
ctx.drawImage(this,0,0,60,60,0,0,120,120);
}
So you OK 了
Clear the canvas
ctx.clearRect
Keep painting Keep clearing , You can achieve animation
But wechat applets at this time , If the performance is not good, it will crash , So simple animation is still used in wechat applet CSS3 Good completion .
边栏推荐
- FPGA integrated project - image edge detection system
- Telecom Customer Churn Prediction challenge baseline [AI competition]
- P1739 expression bracket matching problem solution
- Database | simple hospital patient appointment system based on opengauss
- [golang from introduction to practice] student achievement management system
- MySQL uses explain to analyze SQL execution plans to help find performance bottlenecks
- 13. Unity2d horizontal version of two-way platform that can move up, down, left and right (two-way walking + movable + independent judgment) + random platform generation
- Full revolutionary Siamese networks for object tracking translation
- Cmake binary installation
- 55. Jumping game
猜你喜欢

Digital twin demonstration project -- Talking about simple pendulum (4) IOT exploration

Detailed notes on pytoch building neural network

Robot operation continuous learning thesis (1) original text reading and Translation -- primitive generation strategy learning without catastrophic forgetting in robot operation
![[interview] Why do you need foreach with the for cycle?](/img/f1/3e2b933b91436849eaeb3812c41679.png)
[interview] Why do you need foreach with the for cycle?

Hegong sky team vision training Day2 - traditional vision, opencv basic operation

【MATLAB】(四)MATLAB在线性代数中的应用
![[Game Collection] mobile phones are about to burst, and a collection of six high-quality pyGame games is coming ~ (source code attached)](/img/9e/b237bfa891bd2beb9c1b8a612e9090.png)
[Game Collection] mobile phones are about to burst, and a collection of six high-quality pyGame games is coming ~ (source code attached)

Opencv project practice - credit card recognition
![[Google play access] payment server token acquisition](/img/c6/d095ea2b88a11bf6b4bdd80499932c.png)
[Google play access] payment server token acquisition

SVG 从入门到后悔,怎么不早点学起来(图解版)
随机推荐
Default risk early warning preliminary competition scheme of bond issuing enterprises [AI competition]
FPGA integrated project - image edge detection system
P1135 奇怪的电梯题解
Wechat applet file types and functions
*Yolo5 learning * data experiment based on yolo5 face combined with attention model CBAM
(dkby) DFL learning notes
QT | string generation QR code function
图的认识与存储
Robot operation continuous learning thesis (1) original text reading and Translation -- primitive generation strategy learning without catastrophic forgetting in robot operation
Thesis reading: geotransformer
Alibaba cloud OSS uploads pictures under folders and encounters pits
Svg from entry to regret, why not learn it earlier (graphic version)
Kotlin coroutine (I): foundation and deepening
Decision tree - ID3, C4.5, cart
[target detection] IOU (intersection and combination ratio)
Workspace creation
FPGA综合项目——图像边缘检测系统
Common DOS commands
P1739表达式括号匹配题解
SVG 从入门到后悔,怎么不早点学起来(图解版)