0

Masonry doesn't work on moblie browser (chrome) and it doesn't work in Chrome on refresh (f5). It does work correctly if I load the page in any other browser or if I fully reload the page without using its cache (ctrl+5). It also doesn't work on jsfiddle.

I know it should work because the Masonry site itself does work on these browsers.

I'm using a grid size container for defining the column width, and have tiles with different dimensions:

    .project {
      width: $column_width;
    }

    .grid-sizer {
    width: $column_width;
  }

    .project.oneXtwo {
    width: $column_width;
    height: (2* $column_width);
    }

    .project.twoXone {
    width: (2* $column_width);
    height: $column_width;
    }

    .project.twoXtwo {
    width: (2* $column_width);
    height: (2* $column_width);
    }

Masonry gets initiated on page load:

columnWidth = $(".project").width();
        $(".project").height(columnWidth);
        $(".twoXtwo").height(columnWidth * 2);
        $(".oneXtwo").height(columnWidth * 2);

        container.masonry({
          columnWidth: ".grid-sizer",
          itemSelector: '.project',
          isAnimated:true,
        });

Here is the jsfiddle for the code: http://jsfiddle.net/BartBurg/BtKHL/ note: in jsfiddle it doesn't work on any other browser either.

Edit:

Firefox also has this problem if I reload the page by accessing the website for the second time (not on refresh/reload)

4

1 回答 1

0

解决方案很牵强,可能只会很少发生。

我正在使用 scssphp 解析我的 .SCSS 文件服务器端。我在这件事中包含了我的 SCSS 和 JS 文件:

<!-- Javascript -->
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/masonry.pkgd.min.js"></script>
<script type="text/javascript" src="js/custom.js"></script>

<!-- Stylesheets -->
<link type="text/css" href="style.php/responsive.scss" rel="stylesheet" />

解决方案是在包含任何 Javascript 之前包含样式表:

<!-- Stylesheets -->
<link type="text/css" href="style.php/responsive.scss" rel="stylesheet" />

<!-- Javascript -->
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/masonry.pkgd.min.js"></script>
<script type="text/javascript" src="js/custom.js"></script>

这很有趣,因为我在 jQuery.ready() 上启动砌体:

$( function() {
    ...
    initMasonry(container);
});

function initMasonry(container){
    ...
    container.masonry({
      columnWidth: ".grid-sizer",
      itemSelector: '.project',
          isAnimated:true
    });
    ...
}

如果我用生成的 .css 样式表替换样式表,砌体也可以按预期工作。

我的猜测是,当 Chrome 和 Firefox 看到所有带有 *.js 和 *.css 的行都正确加载并且不会等待挂起的 *.scss 文件时,它们都会触发 DOM 就绪事件。

为什么这适用于整页重新加载(ctrl+f5)而不是刷新(f5),这对我来说是个谜

于 2013-10-16T13:46:22.070 回答