<bdo id='YEJPv'></bdo><ul id='YEJPv'></ul>
    <i id='YEJPv'><tr id='YEJPv'><dt id='YEJPv'><q id='YEJPv'><span id='YEJPv'><b id='YEJPv'><form id='YEJPv'><ins id='YEJPv'></ins><ul id='YEJPv'></ul><sub id='YEJPv'></sub></form><legend id='YEJPv'></legend><bdo id='YEJPv'><pre id='YEJPv'><center id='YEJPv'></center></pre></bdo></b><th id='YEJPv'></th></span></q></dt></tr></i><div id='YEJPv'><tfoot id='YEJPv'></tfoot><dl id='YEJPv'><fieldset id='YEJPv'></fieldset></dl></div>
    <tfoot id='YEJPv'></tfoot>
  • <legend id='YEJPv'><style id='YEJPv'><dir id='YEJPv'><q id='YEJPv'></q></dir></style></legend>

    <small id='YEJPv'></small><noframes id='YEJPv'>

        加载图像时显示加载图标

        时间:2023-09-08

          <small id='6cYBS'></small><noframes id='6cYBS'>

            <bdo id='6cYBS'></bdo><ul id='6cYBS'></ul>
            • <tfoot id='6cYBS'></tfoot>
              <i id='6cYBS'><tr id='6cYBS'><dt id='6cYBS'><q id='6cYBS'><span id='6cYBS'><b id='6cYBS'><form id='6cYBS'><ins id='6cYBS'></ins><ul id='6cYBS'></ul><sub id='6cYBS'></sub></form><legend id='6cYBS'></legend><bdo id='6cYBS'><pre id='6cYBS'><center id='6cYBS'></center></pre></bdo></b><th id='6cYBS'></th></span></q></dt></tr></i><div id='6cYBS'><tfoot id='6cYBS'></tfoot><dl id='6cYBS'><fieldset id='6cYBS'></fieldset></dl></div>
                • <legend id='6cYBS'><style id='6cYBS'><dir id='6cYBS'><q id='6cYBS'></q></dir></style></legend>
                    <tbody id='6cYBS'></tbody>
                  本文介绍了加载图像时显示加载图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在 div 中显示一个背景图像/加载微调器,它将在其中加载一个图像,图像将在完全加载后显示,执行如下操作:

                  I want to show a background image/loading spinner inside a div that will load an image inside of it, the image will show once it's fully loaded doing something like this:

                     <div style="background-image:url('imageThatWillAppearBeforeLoad')"></div>
                  

                  演示(在 jQuery 中)

                  如何使用 Angular2/Ionic2 获得相同的效果?

                  How can I have the same using Angular2/Ionic2?

                  推荐答案

                  创建一个组件,在加载请求的图像之前显示占位符图像,并隐藏请求的图像.加载图像后,隐藏占位符并显示图像.

                  Create a component that shows the placeholder image until the requested image is loaded, and hides the requested image. Once the image is loaded, you hide the placeholder and show the image.

                  @Component({
                    selector: 'image-loader',
                    template: `<img *ngIf="!loaded" src="url-to-your-placeholder"/>
                      <img [hidden]="!loaded" (load)="loaded = true" [src]="src"/>`
                  })
                  export class ImageLoader {
                    @Input() src;
                  }
                  

                  查看它在 Plunker 中的工作.

                  See it working in Plunker.

                  更新

                  现在我更好地理解了要求,这里有一个带有背景图片的解决方案.有点hacky,我更喜欢原来的...

                  Now that I understand the requirements better, here's a solution with background image. It's a little hacky, and I like the original one better...

                  @Directive({
                    selector: '[imageLoader]'
                  })
                  export class ImageLoader {
                    @Input() imageLoader;
                  
                    constructor(private el:ElementRef) {
                      this.el = el.nativeElement;
                      this.el.style.backgroundImage = "url(http://smallenvelop.com/demo/image-loading/spinner.gif)";
                    }
                  
                    ngOnInit() {
                      let image = new Image();
                      image.addEventListener('load', () => {
                        this.el.style.backgroundImage = `url(${this.imageLoader})`;
                      });
                      image.src = this.imageLoader;
                    }
                  }
                  

                  更新插件.

                  这篇关于加载图像时显示加载图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 Ionic 2 中定位弹出框 下一篇:Ionic2 错误:“没有存储提供程序"

                  相关文章

                  最新文章

                  <tfoot id='H0E0g'></tfoot>
                • <small id='H0E0g'></small><noframes id='H0E0g'>

                  <i id='H0E0g'><tr id='H0E0g'><dt id='H0E0g'><q id='H0E0g'><span id='H0E0g'><b id='H0E0g'><form id='H0E0g'><ins id='H0E0g'></ins><ul id='H0E0g'></ul><sub id='H0E0g'></sub></form><legend id='H0E0g'></legend><bdo id='H0E0g'><pre id='H0E0g'><center id='H0E0g'></center></pre></bdo></b><th id='H0E0g'></th></span></q></dt></tr></i><div id='H0E0g'><tfoot id='H0E0g'></tfoot><dl id='H0E0g'><fieldset id='H0E0g'></fieldset></dl></div>
                    <bdo id='H0E0g'></bdo><ul id='H0E0g'></ul>

                    1. <legend id='H0E0g'><style id='H0E0g'><dir id='H0E0g'><q id='H0E0g'></q></dir></style></legend>