jQuery 弹出层脚本

直接贴代码:

 1 $.extend({
 2     closeBox: function (o, x, fn) {
 3         $('#' + o).fadeOut(500, function () {
 4             if (fn && typeof (fn) === "function") { fn(); }
 5         });
 6         if ($('#v_overlay')[0]) { $('#v_overlay').fadeOut(650, function () { $(this).remove(); }); }
 7     },
 8     openBox: function (o, x, fn) {
 9         $.init(o, x, fn); $('#' + o).fadeIn(500);
10     },
11     init: function (o, x, fn) {
12         var w = $(window).width(), h = $(window).height();
13         var bw = $("#" + o).width(), bh = $("#" + o).height();
14         var _top = ((h / 2 - bh / 2) - 50);
15         var boxCss = { "left": ((w / 2 - bw / 2) + "px"), "top": ((_top > 0 ? _top : 10) + "px"), "z-index": "999", "position": "fixed" };
16         $("#" + o).css(boxCss);
17         try {
18             if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
19                 $("#" + o).css("position", "absolute"); location.href = location.href.search(/\?/) > 0 ? location.href.substring(0, location.href.indexOf('#')) : location.href + "#";
20             }
21             if ((window.innerHeight - 40) <= $("#" + o).height()) {
22                 $("#" + o).css({ "position": "absolute", "top": (40 + window.scrollY) });
23             }
24         } catch (e) { }
25         if (x != undefined && $("body").find("#v_overlay").html() == null) {
26             var boxBg = "<div id=\"v_overlay\" style=\"position:absolute;background-color:#000;filter:alpha(opacity=30);opacity:0.3;width:100%;left:0;top:0;z-index:998;border:none;display:none\"></div>";
27             $(boxBg).click(function () { $.closeBox(o, x); }).height($(document).height()).appendTo("body").fadeIn();
28         }
29         $(window).resize(function () {
30             if ($("#" + o).css("display") == "block") {
31                 $('#v_overlay').remove(); $.init(o, x);
32             }
33         });
34     }
35 });

 

posted @ 2014-06-25 13:11  ㄡ落叶风行  阅读(111)  评论(0编辑  收藏  举报