原创

小程序-js-计算图片根据屏幕显示合适的宽高

小程序 - js - 计算图片根据屏幕显示合适的宽高
function imageUtil(e) {
var imageSize = {};
var originalWidth = e.detail.width;
var originalHeight = e.detail.height;
var originalScale = originalHeight / originalWidth;
console.log('originalWidth: ' + originalWidth) console.log('originalHeight: ' + originalHeight) wx.getSystemInfo({
success: function(res) {
var windowWidth = res.windowWidth;
var windowHeight = res.windowHeight;
var windowscale = windowHeight / windowWidth;
console.log('windowWidth: ' + windowWidth) console.log('windowHeight: ' + windowHeight) if (originalScale < windowscale) {
imageSize.imageWidth = windowWidth;
imageSize.imageHeight = (windowWidth * originalHeight) / originalWidth
} else {
imageSize.imageHeight = windowHeight;
imageSize.imageWidth = (windowHeight * originalWidth) / originalHeight
}
}
}) console.log('缩放后的宽: ' + imageSize.imageWidth) console.log('缩放后的高: ' + imageSize.imageHeight) return imageSize
}

正文到此结束
本文目录