JavaScript自定义模拟alert弹出提示框–编码工具

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

JavaScript 自定义模拟alert 弹出提示框–编码工具
使用jQuery ,模拟弹出框alert ,样式模仿iphone 的弹出框,兼容手机、ie 、火狐、chome 等浏览器。

效果如下:
主要使用jQuery 的resize 和scroll 事件,每当滑动浏览器的滚动
条,或者页面重新缩放时,重新定位弹出框的位置,使对话框能够位于页面的正中间:
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 MyJqDialog.prototype.resizeBox = function () {
var box = this.element;
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(document).width();
//Set height and width to mask to fill up the whole screen $(this.overlay).css({'width':maskWidth,'height':maskHeight}); //Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
var scrollT = $(window).scrollTop();
var scrollL = $(window).scrollLeft();
//Set the popup window to center
box.css('top', winH/2 - box.height()/2 + scrollT);
box.css('left', winW/2 - box.width()/2 + scrollL);
};
17
18
19
20
再配合css 样式。

调用如下:
JavaScript
1 2 3 4 5 6 $.myalert({
content: "相关标题",
confirm_btn_click: function (e){ //确认按钮点击事件 $.myalert("getDialog").mydialog("hide");
}
});。

相关文档
最新文档