【问题标题】:Page displaying properly after second load in ie9在ie9中第二次加载后页面正确显示
【发布时间】:2015-09-22 14:23:48
【问题描述】:

我在我的应用程序中使用 jquery BlocksIt 插件,下面是我的部分代码

$(window).load( function() {
$('#container-pinterest').BlocksIt({
  numOfCol: 3,
  offsetX: 4,
  offsetY: 5,
  adjustWidth: true,
  blockElement: 'div'
});
  var currentWidth = 1100;
      var winWidth = $(window).width();
var conWidth;
if(winWidth < 660) {
  conWidth = 440;
  col = 1;
} else if(winWidth < 880) {
  conWidth = 660;
  col = 2;
} else if(winWidth < 1100) {
  conWidth = 880;
  col = 3;
} else {
  conWidth = 1100;
  col = 3;
}
if(conWidth != currentWidth) {
  currentWidth = conWidth;
  $('#container-pinterest').width(conWidth);
  $('#container-pinterest').BlocksIt({
    numOfCol: col,
    offsetX: 4,
    offsetY: 12
  });
}
});    

实际上我在这里加载了一些图片。在 Chrome、Firefox、IE10 和 IE11 中它可以正常工作,但在 IE9 中图像加载缓慢并且 BlocksIt 功能无法正常工作。

当我再次刷新页面时,它工作正常。但是第一次遇到问题

任何帮助

【问题讨论】:

    标签: jquery internet-explorer-9


    【解决方案1】:

    尝试为您的图像添加特殊的onLoad 监听器

    $("img").one("load", function () {
        /* your code here*/
        $(#container-pinterest).BlocksIt({
            numOfCol: 3,
            offsetX: 4,
            offsetY: 5,
            adjustWidth: true,
            blockElement: 'div'
        });
        /* your code here*/
    }).each(function () {
        if (this.complete) $(this).load(); // if image is cached call onload manualy
    });
    

    由于窗口比图像加载得早一点,这就是导致您出现问题的原因。

    【讨论】:

      最近更新 更多