网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序canvas尺寸設置

發布時間:2018-05-03 15:54 所屬欄目:小程序開發教程

微信小程序尺寸設置可使用rpx來標記尺寸,類同rem可在微信小程序中自適應兼容換算不同的機型尺寸。 
但在小程序canvas中,尺寸換算會無效(由于繪畫的滯后),因此需要自適應計算canvas尺寸。

 

一.解決方案

使用小程序提供的getSystemInfo可以獲取當前設備的系統信息,通過獲取當前的設備尺寸,來換算所需要設置的canvas尺寸,從而使得canvas繪圖可以適用于所有設備。

wx.getSystemInfo(OBJECT)

獲取系統信息。

OBJECT參數說明:

success回調參數說明:

示例代碼:

 

				
  1. wx.getSystemInfo({
  2. success: function(res) {
  3. console.log(res.model)
  4. console.log(res.pixelRatio)
  5. console.log(res.windowWidth)
  6. console.log(res.windowHeight)
  7. console.log(res.language)
  8. console.log(res.version)
  9. console.log(res.platform)
  10. }
  11. })
 

二.計算示例

獲取當前窗口寬、高以動態換算需要的canvas尺寸

 

				
  1. wx.getSystemInfo({
  2. //獲取系統信息成功,將系統窗口的寬高賦給頁面的寬高
  3. success: function (res) {
  4. that.width = res.windowWidth
  5. that.height = res.windowHeight
  6. that.radius = 105 / 602 * that.height
  7. }
  8. })


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/24210.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×