Skip to content

scratch组件width的单位问题 #300

@nzhingg

Description

@nzhingg

刮刮卡组件上设置width和height只能使用pax单位,但是在手机端宽高用px是不是不太友好,我看scratch组件的index.js中didMount函数中计算rpx的方法,计算设备宽度用了screenWidth,应该使用windowWidth,我目前是把scratch组件复制到本地的components中,使用本地组件,是可以使用rpx作为单位的。

my.getSystemInfo({
      success: res => {
        // 根据rpx 宽高比计算出实际 px 宽高比
        const pr = res.windowWidth / 750
        this.setData({
          pr,
        })
        this.ctx = my.createCanvasContext('scratch-canvas')
        this.draw(); // 刮刮卡容器初始化
        this.area = pr * this.props.width * pr * this.props.height // canvas �面积
        this.clearPercent = 0; // 被清除像素的所有选区占 canvas 面积的百分比
      }
    })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions