基于jQuery的弹窗小插件
2017-07-14 17:13
239 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>基于jQuery的弹窗小插件</title> </head> <body> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> /* * background:遮罩层背景色 * title:弹窗标题 * msg:弹窗内容 * width:弹窗宽度 * height:弹窗高度 * img:弹窗背景图 * btnArr:按钮数组(最多两个) * fnArr:按钮对应的处理方法数组(和按钮相互对应) * */ function popUp(background,title, msg, width, height,img, btnArr, fnArr) { var maxWidth = $(window).width(); //屏幕最大宽度 var maxHeight = $(window).height(); //屏幕最大高度 //追加遮罩层 var wrap = $('<div></div>'); wrap.css({ "position": "fixed", "top": 0, "left": 0, "z-index": 99, "width": "100%", "height": "100%", "background": background }); $("body").append(wrap); //追加遮罩内容区 var pop = $('<div></div>'); pop.css({ "position": "relative", "top": (maxHeight - height) / 2, "left": (maxWidth - width) / 2, "width": width, "height": height, "background": "#fff url("+img+") no-repeat top 60px center / 146px 80px", "border-radius": "10px", "text-align": "center", "color": "#989898", "box-shadow": "0 0 15px #999" }); wrap.append(pop); //追加标题 if(title != "") { var title = $('<div>' + title + '</div>'); title.css({ "width": "100%", "height": "70px", "line-height": "70px", "font-size": "20px" }); pop.append(title); } //追加内容 if(msg != "") { var msg = $('<div>' + msg + '</div>'); msg.css({ "font-size": "14px", "padding": "90px 0 0 0" }); pop.append(msg); } //追加按钮 if(btnArr != "") { var btnWrap = $('<div></div>'); btnWrap.css({ "position": "absolute", "bottom": 0, "left": "5%", "width": " 90%", "display": "block", "text-align": "center", "font-size": "17px", "border-top": "1px solid #ddd" }); msg.append(btnWrap); $.each(btnArr, function(i, v) { var btn = $('<a>' + v + '</a>'); btn.css({ "display": "inline-block", "width": "48%", "padding": "15px 0", "color": "#00C3AB", "cursor": "pointer" }); btn.click(fnArr[i]); btnWrap.append(btn); }); } } function fnSure() { alert("确定"); } function fnCancel() {
document.body.remove("wrap"); alert("取消"); } popUp("#ccc","温馨提示", "确定融合氢气和氧水吗?", 300, 250,"http://wcmtest.uicredit.cn/H5/personal/images/pic@2x.png", ["取消", "确定"], [fnCancel, fnSure]); </script> </body> </html>
相关文章推荐
- AsyncBox 一款基于 jQuery 的弹窗插件 [2011-9-15] v1.4.5 版
- 基于jquery的上传插件Uploadify
- jcarousellite.js 基于Jquery的图片无缝滚动插件
- jQuery:收集一些基于jQuery框架开发的控件/jquery插件
- 基于jquery的多功能软键盘插件
- 基于jQuery和Flash的多文件上传插件uploadify在asp.net下session丢失解决方案
- btFormbuilder.js 一个基于bootstrap的jquery插件,用于生成form表单
- 基于JQuery的轮播图插件nivo-slider使用教程
- [jQuery插件] Sly:灵活的基于ITEM的滚动插件
- 基于jQuery炫酷图片预览Lightbox插件
- 30个基于jQuery的日期时间选择插件
- 基于JQuery的6个Tab选项卡插件
- 4k项目基于jquery写的表格及分页的插件
- 基于jQuery的懒加载插件
- 基于HTML5 canvas圆形倒计时器jQuery插件
- 分享一些基于jquery功能强大的LightBox灯箱效果插件
- 基于jquery的lazy loader插件实现图片的延迟加载[简单使用]
- 基于jQuery的淡入淡出可自动切换的幻灯插件打包下载