Created
August 15, 2011 10:11
-
-
Save HungYuHei/1145997 to your computer and use it in GitHub Desktop.
把一个元素放在屏幕的中心位置
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.fn.center = function () { | |
this.css('position','absolute'); | |
this.css('top', ( $(window).height() - this.height() ) / +$(window).scrollTop() + 'px'); | |
this.css('left', ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + 'px'); | |
return this; | |
} | |
//这样来使用上面的函数: | |
$(element).center(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment