1
晚上好,jquery masonry image append
我遇到了砌體問題。
這是我的所有相關代碼:
var $test;
var $iterator = 0;
$(document).ready(function() {
$("#demo-input").tokenInput("php-example.php" ,{
classes: {
tokenList: "token-input-list-facebook",
token: "token-input-token-facebook",
tokenDelete: "token-input-delete-token-facebook",
selectedToken: "token-input-selected-token-facebook",
highlightedToken: "token-input-highlighted-token-facebook",
dropdown: "token-input-dropdown-facebook",
dropdownItem: "token-input-dropdown-item-facebook",
dropdownItem2: "token-input-dropdown-item2-facebook",
selectedDropdownItem: "token-input-selected-dropdown-item-facebook",
inputToken: "token-input-input-token-facebook"
},
hintText: "Type in the names of your Tags",
noResultsText: "No results",
searchingText: "Searching..."
});
});
var $container = $('#container');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector: '.box',
columnWidth: 1,
isAnimated: !Modernizr.csstransitions
});
});
$(document).ready(function() {
$("input[type=button]").click(function() {
$.ajax({ url: "generatehtml.php",
data: {action: $(this).siblings("input[type=text]").val()},
type: 'post',
dataType: "json",
success:
function(response){
$test=response;
$iterator = $test.length;
for (i=0; i<10; i++){
var $boxes = $(balls($iterator));
$container.append($boxes).imagesLoaded(function(){$container.masonry('appended', $boxes);});
}
var $boxes = $('<div class="box" STYLE="color: rgba(255, 255, 255, 1);">These results are ranked from<BR> most similar, to least similar.<BR>The percentage below each game <BR>indicates how similar to the <BR>original input that game is.<BR></div>');
$container.prepend($boxes).masonry('reload');
}
});
});
});
window.onscroll = scroll;
function scroll() {
var $boxes = $(balls($iterator));
$container.append($boxes).imagesLoaded(function(){$container.masonry('appended', $boxes, true);});
}
//+'<img src="timthumb.php?src='+$test[$iterator][2]+'&q=100&w=300"/>' Replace this with the one below when timthumb is whitelisted
function balls($i){
$iterator -= 1;
var $width = 7.5;
return ('<div class="box">'
+''+$test[$iterator][1][2]+''
+'<img src="'+$test[$iterator][2]+'" width="280" height="160"/>'
+'<div id=boxBottom>'+Math.floor($test[$iterator][0]*100)+'%</div>'
+'</div>');
}
我期望行爲: 加載頁面,從第二搜索欄選擇的遊戲,點擊 '提交'。
填充10個結果,滾動時填充更多結果。
但格式化到處都是,我知道你應該使用imagesLoaded()插件,但我這樣做。
不管怎麼說,這是有問題的網站:
http://newgameplus.nikuai.net/TEST/ (第一搜索欄不BTW工作,所以忽略)
任何決議將不勝感激。非常感謝。
目前仍然在說,FireFox的一些重疊。 我不認爲我正確使用該插件,主要是因爲我不知道它是如何工作的。 – Adola
您的測試代碼有2個columnWidth,請更新爲280值。 – JonWarnerNet
更新後,Chrome仍然可以正常運行,但Firefox仍然存在問題。說實話,我的圖像每次都不會有相同的寬度,其中一些病人的尺寸不同,所以我不確定這樣做會起作用。 在我已經在腳本中調用imagesLoad()之後再次調用它嗎? 我在這裏說: $ container.append($ boxes).imagesLoaded(function(){$ container.masonry('attached',$ boxes);}); – Adola