【问题标题】:JQuery Masonry ! Update columnWidth On Window ResizejQuery砌体!在窗口调整大小时更新 columnWidth
【发布时间】:2011-12-12 12:54:37
【问题描述】:

我正在研究响应式布局,我也在使用 JQuery Masonry。

我正在使用以下脚本来获取当前列宽。

var curWidth; 
var detector;

detector = $('.magic-column');
curWidth = detector.outerWidth(true);

$(window).resize(function(){
    if(detector.outerWidth(true)!=curWidth){
        curWidth = detector.outerWidth(true);
    }
});

我的 JQuery Masonry 初始化脚本是这样的..

$(window).load(function(){
     $(function (){
            $wall.masonry({
                    singleMode: true, 
                    columnWidth: curWidth, // This needs to be update on window load & resize both //
            });
     });
});

我的第一个脚本正确获取宽度,但在砌体中宽度没有更新...... 如何实现加载和调整大小功能,以便我的 curWidth 将在砌体以及窗口调整大小时更新

【问题讨论】:

    标签: jquery jquery-masonry window-resize


    【解决方案1】:

    resize后需要设置砌体的columnWidth:

    $(window).resize(function(){
        if(detector.outerWidth(true)!=curWidth){
            curWidth = detector.outerWidth(true);
            $wall.masonry( 'option', { columnWidth: curWidth });
        }
    });
    

    你可以在这里阅读更多关于砌体方法的信息:http://masonry.desandro.com/methods.html

    【讨论】:

    • 您好,您在回答中分享的链接已失效。
    【解决方案2】:

    bindResize 可用于在使用流体布局时调整容器中所有项目的大小(bindResize 在 https://github.com/desandro/masonry/blob/master/dist/masonry.pkgd.js 中

    $container.masonry({
        itemSelector: '.container'
    });
    
    $(window).resize(function () {
        $container.masonry('bindResize')
    });
    

    【讨论】:

      猜你喜欢
      • 2013-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-07
      • 1970-01-01
      • 2016-07-08
      • 2015-04-26
      • 1970-01-01
      相关资源
      最近更新 更多