自动垂直居中的js

时间:2020-12-11 14:45:21
var _htmlheight;
function start(){
_htmlheight=document.body.scrollHeight;
resize();
/*$("#copyright").css({(left:$(window).width()-1000)/2+"px"});
$("#content").css({height:$(window).height()-59-208+"px"});
$(".inner_content").css({top:_top+"px"});
$(window).bind('resize',function(){
_top=($(window).height()-59-208)/2>208?($(window).height()-59-208)/2:208;
$("#copyright").css({(left:$(window).width()-1000)/2+"px"});
$("#content").css({height:$(window).height()+$(window).scrollTop()-59+"px"});
$(".inner_content").css({top:_top+"px"});
});
$(window).bind('scroll',function(){
$("#content").css({height:$(window).height()-208+"px"});
});*/
$(window).bind('resize',function(){
resize();
});
}
function resize(){
var _newHeight=$(window).height()-59<_htmlheight?_htmlheight:$(window).height()-59;
$("#content").css({height:_newHeight-208+59+"px"});
var _contentHeight=(_newHeight-208+59-50)/2<30?30:(_newHeight-208+59-50)/2;
$(".inner_content").css({top:_contentHeight+"px"});
document.getElementById("copyright").style.left=($(window).width()-1000)/2+"px";
}

没注释的部分对IE6和7以外的浏览器都是有效的。为了解决IE6和7只能写固定高度。否则最小高度无效了,没空深究,先MARK。