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;   
}
//调用方法
$('#d').center()

 

posted @ 2012-05-23 10:15  yanqing07  阅读(624)  评论(0编辑  收藏  举报