1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- $.fn.centerInClient = function(options) {
-
-
-
-
-
-
-
-
-
- var opt = { forceAbsolute: false,
- container: window,
- completeHandler: null
- };
- $.extend(opt, options);
-
- return this.each(function(i) {
- var el = $(this);
- var jWin = $(opt.container);
- var isWin = opt.container == window;
-
-
- if (opt.forceAbsolute) {
- if (isWin)
- el.remove().appendTo("body");
- else
- el.remove().appendTo(jWin.get(0));
- }
-
- el.css("position", "absolute");
-
- var heightFudge = isWin ? 2.0 : 1.8;
- var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
- var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;
- el.css("left", x + jWin.scrollLeft());
- el.css("top", y + jWin.scrollTop());
-
- if (opt.completeHandler)
- opt.completeHandler(this);
- });
- }
|