Many developers may encounter image distortion during the development of small programs, because the image label of the small program must be set to its width and height, otherwise, if the image width is higher than the size of the original image. We often see the following illustration: but fixed width and height causes some ...,
Summary: Many developers may encounter image distortion during the development of small programs, because the image label of the small program must be set to its width and height, otherwise, if the image width is higher than the size of the original image. We often see the following illustration: but fixed width and height causes some problems...
Many developers may encounter image distortion during the development of small programs, because the image label of the small program must be set to its width and height, otherwise, if the image width is higher than the size of the original image. We often see the following illustration:Function imageLoad (e, zhi, img, or) {var 1_wwidth = 0; wx. getSystemInfo ({success: function (res) {console. log (1); required wwidth = res. required wwidth ;}}) var $ width = e. detail. width, // Obtain the true width of the image $ height = e. detail. height, // Obtain the true height of the image. ratio = $ width/$ height; // The actual width and height of the image. // console. log (e); if (or = 'height') {var viewWidth = zhi * ratio, // set the image display width viewHeight = zhi; if (viewWidth/2> 1_wwidth) {console. log ("your image has exceeded the screen width") ;}} else {var viewWidth = zhi, // set the image display width viewHeight = zhi/ratio;} var image = img; // use the datadata-index of the image as the key of the image object, and then store the image's wide and high value image%e.tar get. dataset. index] = {width: viewWidth, height: viewHeight} return image;} module. exports = {imageLoad: imageLoad} And add code in js:
Var imgload = require ('.. /.. /utils/imgload. js ') Page ({data: {images :{}}, // when the image is loaded, the imageLoad function imageLoad: function (e) {var that = this is called; // imageLoad (e, zhi, img, or) // -- e: the trigger event after the image is loaded. zhi: you need a fixed width (height) value. img: the variable that saves the image's wide and high values. or: specifies the width to be fixed. the default value of height is fixed width var imgs = imgload. imageloactive (e, 200, this. data. images, 'height') this. setData ({images: imgs}) ;}, onLoad: function () {}, onReady: function () {// page rendering completed },}) Add code in wxml:
However, this method has a disadvantage, which may be unacceptable to some users: The image is displayed only after the value is complete, so there is a delay.
|
What are the solutions to image distortion during applet development? For more information, see other related articles in the first PHP community!