同位素:在布局前调整元素大小

Isotope: Resize elements before reLayout

本文关键字:元素 调整 布局 同位素      更新时间:2023-09-26

我想调整同位素网格中的一些元素的大小。

希望每次窗口大小调整时都发生这种情况。我只是想在同位素的reLayout功能之前。

我可以这样做吗?在布局之前有回调吗?

谢谢!

我找到了一个方法。我已经用居心砌筑模式扩展了同位素。在扩展的调整函数中,我对同位素元素进行了调整,然后触发了一个大小调整(不知道这是不是一个正确的方法),这就成功了。

现在每次同位素想要重新布局,就在它之前,我调整元素的大小!

代码如下:

$.Isotope.prototype._masonryResizeChanged = function () {
            //  Resize elements
            //Code that sets a new width for all elements
            // Force a relayout
            $('#container').isotope( 'reLayout');
            //Rest of the overriden method
            var prevColCount = this.masonry.cols;
            // get updated colCount
            this._getCenteredMasonryColumns();
            return ( this.masonry.cols !== prevColCount );
        };