[Turn]ionic or Angularjs picture display compression problem resolution or display an area of a larger picture, cropping the display

Source: Internet
Author: User

We know that displaying images in HTML is usually tagged with an img control, and of course resizing is easy.

However, a specific IMG size will appear, showing a larger size and a length-to-width ratio that does not match the specific IMG size. and caused the compression problem, the picture squeeze is very serious, looks very uncomfortable.

This time can be used in CSS background-image this property to solve. Use the div tag instead of the IMG tag and set the div's background image.

Because Background-image has a lot of properties to use, it is generally easy to meet the needs, such as Background-size, Background-position, and so on.

In ionic or ANGULARJS, it is easy to customize it as an instruction for convenience, that is, Directive

Examples are as follows:

. directive (' backimg ', function () {    return function (scope, element, attrs) {        attrs. $observe (' backimg ', function (value) {            element.css ({                ' background-image ': ' url (' + value + ') ', '                background-size ': ' Cover ', '                background-position ': ' Center '            }    );})

Then use this:

<div class= "back-img" back-img= "{{info.picture_url}}" style= "height:50px;width:50px;" ></div>

Transferred from: http://blog.csdn.net/wy250864144/article/details/54586010

[Turn]ionic or Angularjs picture display compression problem resolution or display an area of a larger picture, cropping the display

Related Article

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.