聘我网

新概念招聘3.0

jQuery如何最方便地实现div居中?

vote up0vote downstar

rt....

 

1 个答复

vote up0vote downcheck
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

然后这样调用:

$(element).center();
链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.