0
基本上,我試圖:獲取父母的身高,減去孩子的身高,將結果除以2,然後使用結果作爲孩子上邊距的值。它工作正常,但只在第一個div。其他人獲得相同的價值。jQuery each()得到相同的結果
這裏是jQuery的:
function update()
{
var container = $('.container');
var inside = $('.inside');
inside.each(function()
{
var cont_height = container.outerHeight();
var inside_height = inside.outerHeight();
var x = (cont_height - inside_height)/2,
x = Math.floor(x);
$(this).css("marginTop", x);
});
}
$(document).ready(function()
{
update();
});
$(window).resize(function()
{
update();
});
我提前道歉,如果這已經回答過了。我試圖看,但我似乎無法拿出正確的關鍵字。
這裏的小提琴:http://jsfiddle.net/y29S4/4/
非常感謝你。
你是真棒。非常感謝你。 – Catcher