我正在尝试使用搜索查询加载图像,然后使用jQuery Blocks It插件(BlocksIt.js)定位它们。这是相关的javascript:
<script>
function getResults(query, max, $selector)
{
$selector.html("Loading...");
$.getJSON('/search', {query: query, max: max}, function(data) {
var items = data;
$selector.html("");
for(var i=0; i<data.length; ++i)
$selector.html($selector.html()+"<div class='img-holder' ><img class='search-image' src='"+ data[i] +"' /></div>");
});
$selector.waitForImages({
finished: function(){
$selector.BlocksIt({
numOfCol: 4,
offsetX: 1,
offsetY: 1
});
},
waitForAll: true
});
$selector.css({height: '500px', overflow: 'auto'});
}
jQuery(function($) {
$('form[data-async]').live('submit', function(event) {
getResults($('#db-search').val(), 20, $('.search-results'));
$('.search-results').BlocksIt({
numOfCol: 4,
offsetX: 1,
offsetY: 1
});
event.preventDefault();
});
});
</script>
DOM就是这样:
<div class='row-fixed'>
<div class='span4'>
<form data-async class="search-form navbar-search pull-left" action='/search'>
<input type="text" id='db-search' class="search-query" name='query' placeholder="Search" />
<input type='hidden' name='max' value=20 />
</form>
<div class="search-results" style="width: 100%; height:500px; position:relative;">
</div>
</div>
</div>
我正在调用BlocksIt()函数两次,一次调用,一次调用图像。我也尝试过一次(在图像加载之前和之后),但它似乎不起作用。显示的图像宽度等于div.search-results
宽度的100%。但是当我在Chrome开发工具控制台窗口中调用该功能时,在加载图像后,将其作为:
$('.search-results').BlocksIt({
numOfCol: 4,
offsetX: 1,
offsetY: 1
});
图像对齐并完美调整大小。请帮我正确地做。
答案 0 :(得分:0)
永远不会调用此代码!
jQuery(function($) {
$('form[data-async]').live('submit', function(event) {
getResults($('#db-search').val(), 20, $('.search-results'));
$('.search-results').BlocksIt({
numOfCol: 4,
offsetX: 1,
offsetY: 1
});
event.preventDefault();
});
});