当我试图获取ID为#content的元素的宽度时它只返回0
奇怪的是,在JSFiddle上它似乎工作得很好http://jsfiddle.net/4urJT/5/
//<![CDATA[
$(document).ready(function () {
/*alert($('#container').width()); */
var columnCount = 4;
var gutter = 15;
$('.post').width(function() {
var calculatedColumnWidth = (((($('#content').width() - ((columnCount*gutter) - gutter)) / columnCount) / $('#content').width()) * 100)+'%';
return calculatedColumnWidth;
});
$( window ).resize(function() {
$('.post').width(function() {
var calculatedColumnWidth = (((($('#content').width() - ((columnCount*gutter) - gutter)) / columnCount) / $('#content').width()) * 100)+'%';
return calculatedColumnWidth;
});
});
var container = $('#content');
container.masonry({
itemSelector: '.post',
gutter: gutter,
});
});
//]]>
我刚刚明白了。我有一个CSS类。post left over,内边距为10px,边框为1px,并在#contentdiv中添加800+px,问题解决了