[英]JQuery Masonry ! Update columnWidth On Window Resize
我正在开发响应式布局,我也在使用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 init脚本是这样的..
$(window).load(function(){
$(function (){
$wall.masonry({
singleMode: true,
columnWidth: curWidth, // This needs to be update on window load & resize both //
});
});
});
我的第一个脚本是正确获取宽度,但在砌体中宽度没有更新...我如何实现加载和调整大小功能,以便我的curWidth将更新为Masonry以及窗口调整大小
您需要在调整大小后设置砌体的columnWidth:
$(window).resize(function(){
if(detector.outerWidth(true)!=curWidth){
curWidth = detector.outerWidth(true);
$wall.masonry( 'option', { columnWidth: curWidth });
}
});
Yuo可以在这里阅读更多关于砌体方法的内容: http : //masonry.desandro.com/methods.html
使用流体布局时,bindResize可用于调整容器中的所有项目( bindResize
位于https://github.com/desandro/masonry/blob/master/dist/masonry.pkgd.js
$container.masonry({
itemSelector: '.container'
});
$(window).resize(function () {
$container.masonry('bindResize')
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.