微信小程序長圖完整滾動顯示


 

 如圖,當插入的圖片的長度超屏幕的高度時,會導致圖片高度被壓縮。

解決的方法是,給圖片外面加一個scroll-view組件實現滾動顯示,添加屬性mode="widthFix"使得圖片寬度完整顯示,詳見代碼。

.wxml

1 <scroll-view scroll-y="{{true}}" style="width:100%;height:{{sysheight}}px;">
2     <view class="img-size">
3         <image src="../../images/liucheng.jpg" mode="widthFix" class="liucheng-img"></image>
4     </view>
5 </scroll-view>

.js

onLoad: function (options) {
    wx.getSystemInfo({//獲取設備屏幕真實高度
      success: (result) => {
        this.setData({
          sysheight:result.windowHeight
        })
      },
    })
  },

.wxss

page{
width: 100%;
height: 100%;
}
.img-size {
  width: 100%;
  margin: auto;

}

.liucheng-img {
  width: 100%;
  height: 100%;
 
}

希望以上解決方案對你有用!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM