0

画面の高さに関係なく、各サイトのコンテンツを真ん中にしたいサイトがあります。

私が達成しようとしているのは、次のようなものです。

#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();
});  

これで私を助けることができる人はいますか?:)

4

4 に答える 4

0
$('.pageclass01').css({height:window_height,marginTop: "-"+($(this).height()/2)});// this here being the pageclass01 element and not window

これはあなたがする必要があるかもしれないことです

于 2013-10-18T08:31:05.343 に答える
0

これを試して、

function fullscreenHeight(){
  var window_height = $(window).height();
  var negative_margin = -(window_height / 2);
  $('.pageclass01').css({'height':window_height,'marginTop':negative_margin+'px'});
}   
于 2013-10-18T08:32:02.313 に答える