Javascript//将边距顶部设置为站点高度的负一半

Javascript//将边距顶部设置为站点高度的负一半,javascript,jquery,html,css,wordpress,Javascript,Jquery,Html,Css,Wordpress,我有一个网站,我希望每个网站的内容是死点,而不管屏幕的高度 我试图实现的是这样的目标: #content {position:absolute; top:50%; height:240px; margin-top:-120px; /* negative half of the height */} 我不知道该如何编码: function fullscreenHeight(){ var window_height = $(window).height(); v

我有一个网站,我希望每个网站的内容是死点,而不管屏幕的高度

我试图实现的是这样的目标:

#content {position:absolute; top:50%; height:240px; margin-top:-120px; /* negative half of the height */}
我不知道该如何编码:

function fullscreenHeight(){      
      var window_height = $(window).height();
      var negative_margin = window_height / 2 * -1;
      $('.pageclass01').css({height:window_height});
      $('.pageclass01').css({margin-top:negative_margin});
}         
fullscreenHeight();           
$(window).bind('resize',function() {      
    fullscreenHeight();
});  
有谁能在这件事上帮我吗?:)

这是您可能需要做的

试试这个

function fullscreenHeight(){
  var window_height = $(window).height();
  var negative_margin = -(window_height / 2);
  $('.pageclass01').css({'height':window_height,'marginTop':negative_margin+'px'});
}   
使用此CSS:

#内容{
位置:固定;
顶部:0;底部:0;
高度:240px;
保证金:自动;
}
/*以下仅用于屏幕太小的情况,例如小手机*/
@媒体屏幕和屏幕(最大高度:240px){
#内容{位置:静态}
}
if($(“.page container”).outerHeight()<$(window.outerHeight()){
$(“.page container”).css({
“top”:($(window.outerHeight()-$(“.page container”).outerHeight())/2
})
}否则{
$(“.page container”).css({
“顶部”:0
})
}
function fullscreenHeight(){
  var window_height = $(window).height();
  var negative_margin = -(window_height / 2);
  $('.pageclass01').css({'height':window_height,'marginTop':negative_margin+'px'});
}   
if ($(".page-container").outerHeight()< $(window).outerHeight()){
    $(".page-container").css({
        'top' : ($(window).outerHeight()-$(".page-container").outerHeight())/2
    })
} else {
    $(".page-container").css({
        'top' : 0
    })
}