最后直接看效果图;不废话,直接上代码,效果图。
(四个文件复制直接可以使用,代码有注释)
思路:当以iphone6/7/8 基础的时候,你就会看到 获取屏幕的宽为350,高为603,这个是微信开发工具的获取的屏幕的数据。 1、 图片在canvas的时候,你可以先设置好高度,和宽度。 2、 当你的canvas需要放到其他的手机屏幕的时,你需要用其他手机的 宽/iphone678宽 高/iphone678高 获取的它(放大或缩小)的比例。3、然后再分别乘以图片的宽、高 4、文字也和图片一样需要设置宽高
js↓↓↓↓↓↓文件 :
// pages/manage/myshare/painter.js
Page({
/**
* 页面的初始数据
*/
data: {
var foo = 'bar';
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
// canvas.js
onReady: function (e) {
},
sening: function(e) {
var that = this;
wx.getSystemInfo({
success: function(res) {
console.log(res.windowHeight)
console.log(res.windowWidth)
console.log(res.pixelRatio)
let windowscale = res.windowHeight/res.windowWidth;
console.log(windowscale)
// 把数据放到data
that.setData({
windowHeight: res.windowHeight,
windowWidth: res.windowWidth,
windowscale:windowscale,
psScal:res.windowWidth/350,//宽//以iphone6/7/8 宽高为基准。用其他也行,进行比例伸缩
psScal1:res.windowHeight/603//高//以iphone6/7/8 宽高为基准。用其他也行,进行比例伸缩
})
},
})
var windowWidth = Number(that.data.windowWidth);
var windowHeight = Number(that.data.windowHeight)