jquery 居中

(function ($) {
        $.fn.extend({
            layerCenter: function () {
                var obj = $(this);
                obj.css({
                    position: "absolute",
                    top: "50%",
                    left: "50%",
                    marginLeft: -obj.width() / 2,
                    marginTop: -obj.height() / 2
                });
            }
        });
    })(jQuery);

调用   $("#div").layerCenter();

posted @ 2012-04-27 14:02  王不惑  阅读(201)  评论(0)    收藏  举报