简体   繁体   English

删除同位素js中的空白

[英]remove white-space in isotope js

There is space in-between each item in my grid. 我的网格中每个项目之间都有空间。 http://okbj.ca/ If you click on most recent or resize the window it will remove the space. http://okbj.ca/如果单击最新的或调整窗口大小,它将删除该空间。 When you refresh the space comes back. 刷新时,空间又回来了。 How can I remove this space for good? 如何永久删除此空间?

I am using the latest versions of chrome, explorer, microsoft edge and firefox. 我正在使用最新版本的Chrome,资源管理器,Microsoft Edge和Firefox。 It seems to not work on all of them. 似乎不适用于所有这些。

在此处输入图片说明

This seems to be a browser-specific issue for you because it appears fine in the latest version of Chrome, Firefox and Safari on OSX. 对于您来说,这似乎是特定于浏览器的问题,因为在OSX的最新版本的Chrome,Firefox和Safari中,它看起来不错。

在此处输入图片说明

It appears the issue occurs on Windows. 看来问题发生在Windows上。 There are two solutions. 有两种解决方案。

Ugly Javascript Hack 丑陋的Javascript Hack

Fire a resize event every second. 每秒触发一个大小调整事件。 This will force the plugin to recalculate the sizes. 这将强制插件重新计算大小。

// cross-browser resize event
var crossBrowserResize = function() {
    var evt = document.createEvent('HTMLEvents');
    evt.initEvent('resize', true, false);
    window.dispatchEvent(evt);
};

// fire the event every second
setInterval(function() {
    crossBrowserResize();
}, 1000);

Use Media Queries Instead 改用媒体查询

This type of grid is easily achievable using pure CSS and some media queries. 使用纯CSS和某些媒体查询可以轻松实现这种类型的网格。 I inspected the elements and they're already using several media queries to adjust how things resize at different breakpoints. 我检查了元素,它们已经在使用几个媒体查询来调整在不同断点处调整大小的方式。

/* 4 columns on tablet landscape and up */
@media screen and (max-width: 1024px) {
  .block {
    width: 25%;
  }
}

/* 2 columns on tablet profile */
@media screen and (max-width: 720px) {
  .block {
    width: 50%;
  }
}

/* 1 column on phone landscape or profile */
@media screen and (max-width: 480px) {
  .block {
    width: 100%;
  }
}

The collapse you want happens only on window resize event (in Chrome). 您想要的折叠仅在窗口大小调整事件(在Chrome中)中发生。 You can dispatch the event once the grid is loaded: 加载网格后,您可以调度事件:

(function fixGrid() {
  var img, grid = document.querySelector('.grid');
  if (grid) {img = grid.querySelector('img');}
  if (img && img.height) {
    window.dispatchEvent(new Event('resize'));
    grid.style.opacity = 1;
  } else {
    if (grid) {grid.style.opacity = 0;}
    setTimeout(fixGrid, 10);
  }
})();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM