全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
自己封装了一个JQuery UI Dialog的插件,这样就可以很方便的使用模态窗口了。先把代码post上来。后续说明再添加上去。我这里面加入了一个拖动事件,原因是有的页面会禁止鼠标选择页面文本和鼠标右键的功能,这会影响到窗口的拖动效果。所以不得已只好自己重新实现一个拖动效果,如果不需要的话可以自行去掉。发表与我的博客 http:/www.chihoo.me/archives/87 /模态窗口插件(function($) $.Dialog = option: title: dialog, height: 300, width: 500, modal: true, resizable: false, external: true, draggable: true , open: function(url, dlgid, options) var op = $.extend(, $.Dialog.option, options); var draggable = op.draggable; op.draggable = false; /关闭ui.dialog的默认拖动事件,改用自定义事件draggable dlgid += new Date().getTime(); / 加入当前时间戳,建立动态ID避免ID冲突 var tempDialog = document.getElementById(dlgid); if (tempDialog != undefined & tempDialog != null) $dialog = $(tempDialog); else $body = $(body); $div = $(); $div.attr(id, dlgid); $body.append($div); $dialog = $(# + dlgid); if (op.external) var iframeWidth = parseInt(op.width) - 10; var iframeHeight = parseInt(op.height); iframe = $().attr( src: url, frameborder: 0, marginwidth: 0, marginheight: 0 ) .css( width: iframeWidth + px, height: iframeHeight + px, margin: 5px ); $dialog.html(iframe); else /嵌入html alert(不支持external: false的模式); $dialog.dialog(op); $dialog.height(parseInt(op.height) - $($dialog).siblings(.ui-dialog-titlebar).outerHeight(); iframe.height(parseInt(op.height) - $($dialog).siblings(.ui-dialog-titlebar).outerHeight(); if (op.param) $dialog.data(param, op.param); $dialog.data(dlgid + callback, options.callback); $(body).data(dlgid, $dialog); /添加窗口拖动事件 if (draggable) $.Dialog.draggable(dlgid); var iframeObj = $(# + dlgid + iframe).get(0).contentWindow; /在iframe的页面中创建window.dialogVal方法,在iframe中使用window.dialogVal()取得传递的参数 iframeObj.dialogVal = function() if ($dialog.data(param) != undefined & $dialog.data(param) != null) return $dialog.data(param); else return ; /在iframe的页面中创建window.closeDialog方法,在iframe中使用window.closeDialog()关闭窗口 iframeObj.closeDialog = function() $.Dialog.close(dlgid); /在iframe的页面中创建window.closeDialogAndReturn方法, /在iframe中使用window.closeDialogAndReturn(returnValue)关闭窗口并返回参数,returnValue为返回的参数 iframeObj.closeDialogAndReturn = function(returnValue) $.Dialog.closeAndReturnVal(dlgid, returnValue); /除去原有的关闭事件并绑定自定义关闭动作 $(# + dlgid).siblings(.ui-dialog-titlebar).find(.ui-dialog-titlebar-close).unbind().bind(click, function() $.Dialog.close(dlgid); ); , /关闭dialog close: function(dialog) if (typeof dialog = string) dialog = $(body).data(dialog); if (dialog = undefined | dialog = null) dialog = $(# + dialog); $(iframe, dialog).remove(); dialog.dialog(close); dialog.parent().remove(); /移除新建的窗口 dialog.remove(); , /关闭dialog并执行返回函数 closeAndReturnVal: function(dlgid, returnValue) var dialog = dlgid; if (typeof dialog = string) dialog = $(body).data(dialog); if (dialog = undefined | dialog = null) dialog = $(# + dialog); if ($(dialog).data(dlgid + callback) != null) $(dialog).data(dlgid + callback).apply(this, returnValue); /执行回调函数并返回value,value可自行定义,在回调函数中自行操作 $.Dialog.close(dialog); , draggable: function(dlgid) $dialog = $(# + dlgid); var bool = false; $dialog.siblings(.ui-dialog-titlebar).css(cursor, move); $dialog.siblings(.ui-dialog-titlebar).unbind().select(function() return false; ).mousedown(function(e) bool = true; $dialog.data(offsetX, e.pageX); $dialog.data(offsetY, e.pageY); $dialog.data(left, $dialog.parent().offset().left); $dialog.data(top, $dialog.parent().offset().top); ).mouseleave(function() bool = false; ); $(document).mouseleave(function() bool = false; ).mouseup(function() bool = false; ).mousemove(function(e) if (!bool) return; var offsetX = $dialog.data(offsetX); var offsetY = $dialog.data(offsetY); var left = $dialog.data(left); var top = $dialog.data(top); v
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年合肥中盐红四方肥业公司春季招聘建设考试参考试题及答案解析
- 2026年大连市普兰店区农业农村局特聘农技员3人建设考试参考试题及答案解析
- 2026年4月重庆市万州区双河口街道办事处公益性岗位招聘2人建设考试备考试题及答案解析
- 中国交建集团2026届春季校园招聘建设考试参考试题及答案解析
- 2026四川宜宾筠连县沐盛农业开发有限公司招聘1人建设考试备考试题及答案解析
- 2026汉中市精神病医院招聘(6人)建设考试备考试题及答案解析
- 2026新干县人民医院招聘见习岗专业技术人员20人建设笔试模拟试题及答案解析
- 泸州市中医医院招聘(4人)建设考试参考题库及答案解析
- 2026广东中山市大涌镇中心幼儿园招聘事业单位编外人员6人建设笔试参考题库及答案解析
- 2026河北廊坊大厂回族自治县夏垫镇棋盘小学公开招聘见习教师建设考试备考题库及答案解析
- 2025年青海青江实业集团有限公司招聘笔试参考题库含答案解析
- 无人机航测基础培训
- k歌沐足合同协议书范文范本
- 光伏发电监理表式(NB32042版-2018)
- 等差数列的通项与求和公式
- 布局经营 绘画构图基础 课件-2022-2023学年高二美术人美版(2019)选择性必修绘画
- 整合营销传播-品牌传播的策划、创意与管理(第3版)课件 第11章 整合视觉传达策略
- 现代女性中医养生与保健
- 五一劳动节学生假期安全教育主题班会课件
- 陕西明瑞资源再生有限公司 3 万吨 - 年废矿物油再生利用项目竣工环境保护验收监测报告
- 重庆岩溶找水物探工作方案
评论
0/150
提交评论