标签:height off code idt fse ace div 计算 str
if
($(
"#cont1"
).css(
"position"
)!=
"fixed"
){
$(
"#cont1"
).css(
"position"
,
"absolute"
);
var
dw = $(window).width();
var
ow = $(
"#cont1"
).outerWidth();
var
dh = $(window).height();
var
oh = $(
"#cont1"
).outerHeight();
var
l = (dw - ow) / 2;
var
t = (dh - oh) / 2 > 0 ? (dh - oh) / 2 : 10;
var
lDiff = $(
"#cont1"
).offset().left - $(
"#cont1"
).position().left;
var
tDiff = $(
"#cont1"
).offset().top - $(
"#cont1"
).position().top;
l = l + $(window).scrollLeft() - lDiff;
t = t + $(window).scrollTop() - tDiff;
$(
"#cont1"
).css(
"left"
,l +
"px"
);
$(
"#cont1"
).css(
"top"
,t +
"px"
);
}
jquery计算出left和top,让一个div水平垂直居中的简单实例
标签:height off code idt fse ace div 计算 str
原文地址:http://www.cnblogs.com/sjqq/p/6363172.html