jQuery中心垂直和水平网页

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jQuery中心垂直和水平网页相关的知识,希望对你有一定的参考价值。

  1. jQuery.fn.center = function() {
  2. this.css("position", "absolute");
  3. this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
  4. this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
  5. return this
  6. };

以上是关于jQuery中心垂直和水平网页的主要内容,如果未能解决你的问题,请参考以下文章