我有一个元素,我需要在屏幕上水平和垂直居中放置,我不是用jQuery做的,但是我怎么做呢,目前我的代码看起来像这样,
$("dd a, dt a, .job_listings a, #similar_jobs a").live("click", function(){
var self = $(this);
$("#overlay").fadeIn('slow');
var targetProcent = 68;
var targetWidth = $(window).width() * (targetProcent / 100);
var targetHeight = $(window).height() * (targetProcent / 100);
var targetX = ($(window).width() - 827) / 2;
var targetY = 75;
$('#lightbox').load(self.attr("href"));
//usePointFromPostcode(document.getElementById('postcode').value, placeMarkerAtPoint)
$('#lightbox').css({
"position": "absolute",
"top": $(window)+75+"px",
"left": targetX+"px"
}).fadeIn('slow');
//$('html, body').animate({scrollTop:0}, 'slow');
return false;
});
答案 0 :(得分:1)
@udders;也许你可以为你的元素定义position :absolute
的 CSS 强>
div{
width:300px;
height:300px;
top:50%;
left:50%;
margin-top:-150px;
margin-left:-150px;
}
给margin
height & width
查看更多链接: