jQuery 弹出层脚本

本文探讨了如何使用jQuery实现动态网页交互效果,并通过JavaScript调整页面元素布局,提升用户体验。主要内容包括创建自定义弹出窗口、页面元素的平滑过渡动画以及利用窗口大小调整布局的响应式设计。

直接贴代码:

 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 });

 

转载于:https://www.cnblogs.com/baily/p/3807854.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值