- jQuery.fn.center = function () {
- return this.each(function(){
- $(this).CSS({
- position:'absolute',
- top, ( $(window).height() - this.height() ) / 2 + $(window).scrollTop() + 'px',
- left, ( $(window).width() - this.width() ) / 2 + $(window).scrollLeft() + 'px'
- });
- });
- }
- //这样来使用上面的函数:
- $(element).center();
- //该片段来自于http://www.codesnippet.cn/detail/040120131272.html
来源: http://www.codesnippet.cn/detail/040120131272.html