div页面居中

没事瞎写点东西..写了个div垂直居中页面中的代码.

$(document).ready(function(){
jQuery.fn.center = function(){
  var width = parseInt(($(window).width() - $(this).width() ) / 2 + $(window).scrollLeft()),
    height = parseInt(($(window).height() - $(this).height()) / 2 +$(window).scrollTop());
  $(this).css({
    left:width+'px',
    top:height+'px',
    position:'absolute'
  })
};
$('#text').center();//调用方式
})

<p id="text" style="300px;height:300px;border:#000 1px solid">ssss</p>

原文地址:https://www.cnblogs.com/taoze/p/2563334.html