晚上好,
我遇到了与砌体有关的问题。
这是我的所有相关代码:
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/ (第一个搜索栏不起作用,所以忽略它)
任何决议都将不胜感激。非常感谢。
答案 0 :(得分:2)
尝试将columnWidth更改为与框中的图像相同:
$container.imagesLoaded( function(){
$container.masonry({
itemSelector: '.box',
columnWidth: 280,
isAnimated: !Modernizr.csstransitions
});
});
更新专栏:
$container.append( $boxes ).imagesLoaded( function(){$container.masonry( 'appended', $boxes);});
为:
$container.append( $boxes ).masonry('appended', $boxes);
我还认为你应该修改你的$(document).ready
部分。您当前有2个,并且在两者之间检索#container
元素。我认为您应该只有一个,并确保在$container
中提取$(document).ready
。
更新的代码:
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: 280,
isAnimated: !Modernizr.csstransitions
});
});
$("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 ).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' );
}
});
});
});