我使用的是絕對定位佈局(類似位Pinterest的)
所以我還需要重新計算window.resize的位置:而且因爲這事件不是在dom準備好時觸發的,我手動執行。現在
$(document).ready(function(){
$(window).resize();
});
$(window).resize(setupBlocks);
,此功能setupBlocks的HTML元素的尺寸檢查,計算新的位置
function setupBlocks() {
if ($('.fancyContent').length > 0) {
if ($('.rightFixed').length > 0) $('.fancyContent').width($(window).width() - 320)
windowWidth = $('.fancyContent').width();
//colWidth = $('.fancyContent .widgetHelp').outerWidth();
blocks = [];
//console.log(blocks);
colCount = Math.floor(windowWidth/(colWidth + margin * 2));
for (var i = 0; i < colCount; i++) {
blocks.push(margin);
}
$('.fancyContent .widgetHelp').css({
'position': 'absolute',
'width': colWidth
});
positionBlocks();
var topFooter = $('.fancyContent .widgetHelp:last').offset().top + 350;
$('footer').css({
'position': 'absolute',
'top': topFooter
});
//console.log(topFooter);
$('.fancyContent').css('visibility', 'visible');
$('#load').remove();
//console.log($('#load').length);
}
}
function positionBlocks() {
$('.fancyContent .widgetHelp').each(function() {
var min = Array.min(blocks);
var index = $.inArray(min, blocks);
var leftPos = margin + (index * (colWidth + margin));
$(this).css({
'left': leftPos + 'px',
'top': min + 'px'
});
blocks[index] = min + $(this).outerHeight(true) + margin;
});
}
意外的是,因爲預計執行。但是,直到窗口調整大小後,職位計算得並不是很好。然後這些職位變得確切。
我知道這是一個遠射。但任何想法爲什麼它可能會有不同的表現?
它的更好,如果你測試自己:http://209.51.221.243/integracion/login.php
當頁面加載時,div的幾乎細(其中有些是垂直接觸),但如果調整股利的div得到很好地定位。任何思想?
我沒有通讀你的代碼,但在這種情況下,你爲什麼不使用css'position:fixed'定位呢? –
這不適合模板。用戶將看到相同的職位,即使滾動... –