0
点赞
收藏
分享

微信扫一扫

服务器分析和监控

小月亮06 2023-09-12 阅读 19

问题:

        如题

解决办法:

        

  <div #imgRoot style="position: absolute; background-color: slategray; width: 100%; height: 100%;">
    <div #imgContainer style="background-color: slategray; padding: 3px 0; display: flex; flex-direction: row; justify-content: center; align-items: center; width: 100%;">
      <img #img [src]="imgSrc" width="90%" alt=""/>
      <ng-container
        *ngIf="(img.height < imgRoot.offsetHeight)?
          imgContainer.setAttribute('style', imgContainer.getAttribute('style')+';height: 100%')
          : imgContainer.setAttribute('style', imgContainer.getAttribute('style')+';height: auto')">
      </ng-container>
    </div>
  </div>

额外说明:

        此写法针对简单界面有效,因为ngif中有函数,会触发多次调用,如果含复杂界面可能会有性能问题。

        求轻快实现可以一步在html模板里完成,而不用去ts中搞一堆代码

        如果有其他简单实现也可以在评论区告诉我,谢谢了

举报

相关推荐

0 条评论