我使用这个jQuery脚本来根据浏览器窗口分辨率来居中我的div.但是我无法让它发挥作用.我在这里错过了什么?
我在jsFiddle中发布了它以便更好地理解这里http://jsfiddle.net/9wvt3/
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
return this;
}
$(#main).center();
Run Code Online (Sandbox Code Playgroud)
这个:
$(#main).center();
Run Code Online (Sandbox Code Playgroud)
应该是:
$('#main').center();
Run Code Online (Sandbox Code Playgroud)
请注意,'在$()函数的参数.
| 归档时间: |
|
| 查看次数: |
241 次 |
| 最近记录: |