【文件属性】:
文件名称:jQuery常用
文件大小:14KB
文件格式:TXT
更新时间:2016-02-22 11:52:07
jQuery js
49. 如何把一个元素放在屏幕的中心位置:
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();