开发者社区
社区提问意见反馈
开发者钉组织
扫描二维码
加入支付宝开发者钉组织
基础 api
基础
应用级事件
界面
导航栏
tabbar
路由
交互反馈
下拉刷新
联系人
选择城市
选择日期
动画
画布
canvas
canvasrenderingcontext2d
canvaspattern
offscreencanvas
旧版接口(停止更新)
地图
计算路径
键盘
滚动
节点查询
选项选择器
级联选择
设置窗口背景
设置页面是否支持下拉
字体
跳转
多媒体
缓存
文件
位置
网络
设备
worker
数据安全
分享
收藏
自定义通用菜单
更新管理
web-view组件控制
升级支付宝最新版本
隐私信息授权
小程序广告
开放能力 api
开发 > api > 基础 api > 界面 > 画布 > canvas > canvas.cancelanimationframe
评论
收藏
我的文档
设置

canvas.cancelanimationframe(number requestid)

基础库  或更高版本; 若版本较低,建议采取 兼容处理

主体: 企业支付宝小程序个人支付宝小程序

取消一个由 canvas.requestanimationframe 注册的函数。

number requestid

canvas.requestanimationframe 返回的 id

代码示例
.js
.axml
page({
    oncanvasready() {
        my.createselectorquery().select('#canvas').node().exec((res) => {
            const canvas = res[0].node
            const ctx = canvas.getcontext('2d')
            this.canvas = canvas
            this.ctx = ctx
            this.x = 0
            this.y = 0
            this.draw()
        })
    },
    
    draw(timestamp) {
        console.log(timestamp)
    
        const { ctx, canvas, x, y } = this
    
        // 清空画布
        ctx.clearrect(0, 0, canvas.width, canvas.height)
    
        // 绘制方块
        ctx.fillstyle = "red"
        ctx.fillrect(x, y, 50, 50)
    
        this.x  = 0.5
        this.y  = 0.5
    
        let id = canvas.requestanimationframe(this.draw.bind(this))
    
        canvas.cancelanimationframe(id)
    }
})
<canvas id="canvas" type="2d" onready="oncanvasready">canvas>
内容没有解决您的问题?您还可以前往 或 寻求帮助
凯发k8官方网娱乐官方 copyright © 2022 支付宝(杭州)信息技术有限公司  | icp证浙b2-20160559
该文档对你是否有帮助?
当前页面目录
网站地图