1

嗨,我已经使用 Sencha touch2 完成了应用程序。在轮播中,我们在控制器级别从 Web 服务动态绑定图像。当我们在轮播中移动/滑动图像时,下一张图像需要时间来加载/显示在轮播中。如果加载原始图像需要时间,那么它将在轮播中显示默认加载蒙版。根据我们的要求,如果在滑动轮播时加载原始图像需要时间,我们需要在轮播中显示默认图像。加载原始图像后,无需显示默认图像,显然加载蒙版也将消失。谁能告诉我如何实现这个煎茶 touch2?

我的查看页面代码:

Ext.define('SLS.BRND.WEB.view.ProjectsView', {
  extend: 'Ext.Panel',
  requires: [        
  'Ext.Carousel'
  ],
  id: 'projectprofile',
  xtype: "projectspage",
  config: {
    autoDestroy: true,
    fullscreen: true,       
    layout: {
      type: 'vbox'
    },
    items: [{
      xtype: 'panel',
      layout: 'fit',
      flex: Ext.os.is.Phone ? 5 : 5,
      items: [{
        xtype: 'carousel',
        direction: 'horizontal',
        directionLock: true,
        id: 'ImgId',
        flex: Ext.os.is.Phone ? 5 : 5,                          
        config: {
          fullscreen: true                               
        }
      }]
    }]
  }
});

我的控制器页面代码:

var retrievedObject = localStorage.getItem('ProjectDetails');
jsonObj = Ext.decode(retrievedObject);
var cmp = Ext.getCmp('ImgId');

if (jsonObj != null) {
  if (jsonObj != null) {
    var itemsoverlay = [];
    if (jsonObj.ProjectMainGalleryRoyalGardenia != null) {
      for (var i = 0; i < jsonObj.ProjectMainGalleryRoyalGardenia.length; i++) {
        var imgURL = jsonObj.ProjectMainGalleryRoyalGardenia[i].ImageUrl;
        var senchaIoProjectImageURL = imgURL;
        var senchabigImage = imgURL;

        var images = [{ url: senchaIoProjectImageURL, bigUrl: senchabigImage}]
        Ext.each(images, function (picture) {
          var img = picture.url;
          var bigImg = picture.bigUrl;
          itemsoverlay.push({
            xtype: 'label',
            html: '<div style="width:' + window.innerWidth + 'px;height:' + SLS.BRND.WEB.Common.Constants.carouselCanvasHeight + 'px;"><img src=' + img + ' style="width:100%;height:100%"/></div>'
          });
        });
      }
    }
    cmp.setItems(itemsoverlay);
    cmp.setActiveItem(0);
  }
}
4

1 回答 1

2

我可以看到的快速解决方案是向包含图片的 div 添加一个 CSS 类,例如:

itemsoverlay.push({
  xtype: 'label',
  html: '<div cls="myDiv" style="width:' + window.innerWidth + 'px;height:' + SLS.BRND.WEB.Common.Constants.carouselCanvasHeight + 'px;"><img src=' + img + ' style="width:100%;height:100%"/></div>'
});

然后在您的 CSS 文件中创建相关的 CSS 类:

.myDiv {
  background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAbvAAAG7wBureguwAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTM5jWRgMAAAAVdEVYdENyZWF0aW9uIFRpbWUANy8yNC8wN7cOTVAAAAzcSURBVHic7dtZU+PKHQXwo9ZiSZYtvLCHeyehklupSlW+/8fI062kimQyBBgW2wjvstXKg5HGi/wHZsAwcH4vgCRLrW4dqbstjDRNUxBRIfXaBSB6yxgQIoH1vR9MAYzjGON4Aq1TJInGNEmesWhET2dbFpQyYJkm3JID2zJ/aH9PCsg4nqA7GCLqDhBPpkiSBInWSNMUOk2hNYcz9LpMZcAwDCjDgGmZMJWC7zoIKwHKbgnWEwNjPGaQPhiNcd2OcNvtI0k0DAMAjPufAAwDhvB5ok2aXdEp0m9/QKeA59iob1XQrFVhmY8LihiQNE1x2brFZesW0ySBaZoMAv20Zr0cDa9Uwh92GqhW/Ac/szYgWmv89/wKnbseDKWgDEaD3getNQwAh7tNbNdDcdu1s1hfLq7RvuvBNE2Gg94VpRRgGPjf1xu0o668bdHC63aEdtSDqTgLTO+TYRizkFzeYDiO1263koDJdIrL1i0MYzYbQPReKWVgOk1w1bpdv83ygnbUQzyZQCmGg94/Q5mIun0MRuPC9QsBSYHZoNxg14o+BmUAk2mC226/eP38H/3BCON4wq4VfShKGej1R4VfdC8EZDAcYZokYD7oI1FKYTAaIZ5MV9fN/zEu2IDoI0jTF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wrQcCUnJseG6JAaEPJUWKSuDNxhlLVobtzVp1E2UiehN0msItOdiqBIXrVwISBj7Knosk0S9eOKLXprVGI6zALviSECgIiGEYONipwzQNdrXoXUsSjcBzsV0L125T+C5W4Hs43GkgTVNohoTeoSTRcGwLvx7swDTXv5K4Omy/17xP1dlVG9NEwxJ2QvSzSFMg0QnKbgm/HuzALa1+9zHPSB/oR/WHI5xftdDtjwBj9s4Wvyuhn0mazmaq0jSFMgw0tirY364Xvnu17MGAzA6QIur2cXPbxWgcI55OkeoUhpqFxQCA7CfRK8ou5zSd/Z6mKUxTwbYtVDwPzVoVvld69P4eFZB543iC7mCIcTzFOJ4gnsRIkhSJTjCdavDhQq/JsiyYyoBpmnAdG45twSs5qJR9cayxzpMDsmyaJPlgPuWLjvTKlFIwjNnPordzn+qHA0L0nnFqikjwf/0qqzzaHOPmAAAAAElFTkSuQmCC);
}

在这里,我只是将占位符图像转换为 Base 64 数据并将其添加为 div 的背景图像。这样,您的默认图像将在真实图片加载之前出现。

通过从 div 中删除 myDiv CSS 类,您可以在加载真实图片后轻松删除默认图片。

希望这可以帮助

于 2012-12-04T17:03:06.807 回答