What are the solutions to image distortion during WeChat applet development?

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.