【问题标题】:How to change javascript option on resizing window?如何在调整窗口大小时更改 javascript 选项?
【发布时间】:2021-02-07 20:57:31
【问题描述】:

当我将移动设备的窗口缩小到 500 像素时,我需要更改脚本中的一个选项。必须很简单,但我无法管理它。当窗口大小为例如 500 像素时,我需要 fitWidth: true 为“假”。

代码如下:

// init Isotope
var $grid = $('#container').isotope({
itemSelector: '.element',
masonry: {
columnWidth: '.element',
fitWidth: true,
horizontalOrder: true
},
filter: function() {
var $this = $(this);
var searchResult = qsRegex ? $this.text().match( qsRegex ) : true;
var buttonResult = buttonFilter ? $this.is( buttonFilter ) : true;
return searchResult && buttonResult;
}
});

希望有人可以帮助我。

【问题讨论】:

  • 您始终可以将 CSS 类附加到您的元素,然后在您的 CSS 文件中使用媒体查询来根据需要进行调整。
  • 你可以借助 css 创建一个响应式页面。

标签: javascript media-queries jquery-events jquery-isotope window-resize


【解决方案1】:

使用 onresize 事件

window.onresize = function() {
  if (screen.width <= 500) {
   console.log("do something");
  }
}

【讨论】:

  • 您能否提供一个关于“做某事”的示例,因为我无法管理它。请简单地将'fitWidth'变为false
  • 我对同位素不熟悉。快速浏览一下,我无法为 fitWidth 重新分配一个新值(因为缓存它的想法?idk)。但有效的是重新分配 $grid 与整个东西(包括fitWidth: false
猜你喜欢
  • 1970-01-01
  • 2016-08-03
  • 2016-07-07
  • 2013-09-17
  • 2016-07-08
  • 2011-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多