不工作,我有以下幾點:jQuery的砌體例如基於<a href="http://masonry.desandro.com/" rel="nofollow noreferrer">jQuery masonry</a>我
的jQuery:
$('#container').masonry({
itemSelector : '.item',
columnWidth: 240
});
jQuery的AJAX:(jQuery的砌體工程第一次success
發生jquery-masonry不起作用如果success
再次發生沒有頁面重新加載。)
success: function(widget_shell)
{
if(widget_shell.d[0]) {
$("#container").empty();
var i = 0;
// creating the div elements
for (i = 0; i <= widget_shell.d.length - 1; i++) {
var j = Math.floor(Math.random() * 200) + 50
var $widget = $("<div class='item col1' style='height:" + j + "px'></div>").appendTo($("#container"));
$("<span>" + widget_shell.d[i].widget_id + " - " + j + "</span>").appendTo($widget);
}
// initialising the jquery masonry plugin
$('#container').masonry({
itemSelector : '.item',
columnWidth: 240
});
}
}
success: function(widget_shell)
{
if(widget_shell.d[0]) {
$("#container").empty();
var i = 0;
// creating the div elements
for (i = 0; i <= widget_shell.d.length - 1; i++) {
var j = Math.floor(Math.random() * 200) + 50
var $widget = $("<div class='item col1' style='height:" + j + "px'></div>").appendTo($("#container"));
$("<span>" + widget_shell.d[i].widget_id + " - " + j + "</span>").appendTo($widget);
}
// initialising the jquery masonry plugin
$('#container').masonry({
itemSelector : '.item',
columnWidth: 240
});
}
}
HTML:(通過jQuery-AJAX動態創建)
<div id="container" style="position: relative; height: 0px;" class="masonry">
<div class="item col1" style="height:154px"><span>39 - 154</span></div>
<div class="item col1" style="height:100px"><span>52 - 100</span></div>
<div class="item col1" style="height:229px"><span>53 - 229</span></div>
<div class="item col1" style="height:126px"><span>55 - 126</span></div>
<div class="item col1" style="height:245px"><span>56 - 245</span></div>
<div class="item col1" style="height:242px"><span>57 - 242</span></div>
<div class="item col1" style="height:146px"><span>58 - 146</span></div>
<div class="item col1" style="height:63px"><span>59 - 63</span></div>
<div class="item col1" style="height:118px"><span>60 - 118</span></div>
<div class="item col1" style="height:249px"><span>61 - 249</span></div>
<div class="item col1" style="height:136px"><span>62 - 136</span></div>
<div class="item col1" style="height:114px"><span>63 - 114</span></div>
<div class="item col1" style="height:152px"><span>64 - 152</span></div>
<div class="item col1" style="height:52px"><span>65 - 52</span></div>
<div class="item col1" style="height:95px"><span>66 - 95</span></div>
</div>
CSS:
.item {
width: 220px;
margin: 10px;
float: left;
background:white;
}
結果:
預計:
當它應該看起來像this interms的div水平和垂直方向對彼此的,向上的。
問:
我在做什麼錯?
爲什麼你'高度:0px'在'#container的div'? –
[Works for me](http://jsfiddle.net/RNA8R/)。 –
@CalvinCheng,我沒有補充說,它會自動生成。 – oshirowanen