代码之家  ›  专栏  ›  技术社区  ›  Raffaele

交换不同大小的图像[Javascript与IE]

  •  1
  • Raffaele  · 技术社区  · 15 年前

    _preload = function(url, placeholderUrl) {
     var img = new Image();
     loading = true;
     var placeholder = new Element("img", {
      src: placeholderUrl
     });
     img.placeholder = placeholder;
     img.onload = function(evt) {
      this.placeholder.src = this.src;
      loading = false;
     }
     img.src = url;
     return placeholder;
    }
    

    alt text 在这里你可以看到视觉上的错误

    2 回复  |  直到 15 年前
        1
  •  2
  •   subhaze    15 年前

    您应该能够在回调函数中调整图像的宽度/高度:

    img.onload = function(evt) {
      this.placeholder.src = this.src;
      this.placeholder.width = this.width;
      this.placeholder.height = this.height;
      loading = false;
    }
    

    例子: Resizing image onLoad

        2
  •  0
  •   Dr.Molle    15 年前

    我想替换 具有 (dom中的img元素)应该解决这个问题,而不是简单地更改placeholder的src属性。