用jQuery写了一个模态框插件感觉挺好看的在博客园分享一下!

大家觉得下面的框框好看么, 水印可以去掉(这个任务交给你们了(~ o ~)~zZ);

"info"框

$("div").confrimModal("<font color=\"green\">成功! </font>", {type:"info", themeColor: "#008B8B"}, true);

"alert"框

$("div").confrimModal("<font color=\"green\">成功! </font>", {type:"alert", themeColor: "green"});

"confrim"框

$("div").confrimModal("确认删除该记录?", {type:"confrim", themeColor: "#0093D5"}, false);

$("div").confrimModal("确认删除该记录?", {type:"confrim", themeColor: "#0093D5"}, true);

code: jquery.beautyDialog.js (使用时将这个引入就可以使用, 方便起见css 并没有抽取出来, 有空再改一改;)

;(function($){
        $.fn.extend({
            /* booleanFactory: {"key": false}*/
            booleanFactory: function(deb){
                if (typeof deb == "boolean") {
                    return {"key": deb};
                }else {// 只要参数类型不为 ‘boolean‘ 默认返回false;
                    return {"key": false};
                }
            },
            /* stringFactory: {"key": ""}*/
            stringFactory: function(param){
                if (typeof param == "string") {
                    var temp = $.trim(param);// 去掉空格
                    return {"key": temp};
                }else {// 只要参数类型不为 ‘string‘ 默认返回"";
                    return {"key": ""};
                }
            },
            /* optionsFactory: {"key": ""}*/
            optionsFactory: function(obj){
                if (typeof obj == "object" && !$.isEmptyObject(obj)) {
                    if (obj.type == undefined || $.isEmptyObject(obj.type)) {// 如果type没有定义或type为空则默认 "alert";
                        return {"type": "alert", "themeColor": "green"};
                    } else {// obj.type 不为空
                        var key = obj.type;
                        switch (key) {
                        case "info":
                            return obj;
                            break;
                        case "confrim":
                            return obj;
                            break;
                        case "alert":
                            return obj;
                            break;
                        default:
                            return {"type": "alert", "themeColor": "green"};
                            break;
                        }
                    }
                    return obj;
                }else {// 只要参数类型不为 ‘object‘ 默认返回object;
                    return {"type": "alert", "themeColor": "green"};
                }
            },
            /* confrimModal 确认模态框组件;*/
            confrimModal: function(msg, options, isOpen){
                var compnet = "";
                var content = this.stringFactory(msg).key;
                var obj = this.optionsFactory(options);
                if (obj.type == "info") {
                    compnet = $(
                            "<div class=\"drag\" style=\"outline: 1px " + obj.themeColor + " solid;background: #FFFFFF; cursor:pointer; box-shadow: 10px 10px 5px #888888; text-align: center;width: 180px; height: auto; margin: 10px; position: fixed;\">"+
                            "<div style=\"background: " + obj.themeColor + "; color: #FFFFFF; text-align: left; padding: 0 0 2px 5px;\">提示信息"+
                                "<label title=\"关闭\" id=\"close\" style=\"float: right; background: url(‘image/close.png‘) no-repeat;\">&nbsp;&nbsp;&nbsp;</label>"+
                            "</div>"+

                            "<div style=\"padding:5px;background: url(‘image/pm.gif‘) no-repeat;background-position:left top;\">"+
                                "<table style=\"padding:20px 0 0 0; font-size:12px; table-layout: fixed; border: 1px solid " + obj.themeColor + ";text-align: center; width: 100%;word-break: break-all;word-wrap:break-word;\">"+
                                    "<tr><td>" + content + "</td></tr>"+"<tr><td></td></tr>"+
                                "</table>"+
                            "</div>"+
                        "</div>"
                    );
                }
                if (obj.type == "confrim") {
                    compnet = $(
                            "<div class=\"drag\" style=\"outline: 1px " + obj.themeColor + " solid;background: #FFFFFF; cursor:pointer; box-shadow: 10px 10px 5px #888888; text-align: center;width: 180px; height: auto; margin: 10px; position: fixed;\">"+
                                "<div style=\"background: " + obj.themeColor + "; color: #FFFFFF; text-align: left; padding: 0 0 2px 5px;\">提示信息"+
                                    "<label title=\"关闭\" id=\"close\" style=\"float: right; background: url(‘image/close.png‘) no-repeat;\">&nbsp;&nbsp;&nbsp;</label>"+
                                "</div>"+

                                "<div style=\"padding: 5px;background: url(‘image/pm.gif‘) no-repeat;background-position:left top;\">"+
                                    "<table style=\"padding:20px 0 0 0; font-size:12px; table-layout: fixed; border: 1px solid " + obj.themeColor + ";text-align: center; width: 100%;word-break: break-all;word-wrap:break-word;\">"+
                                        "<tr><td>" + content + "</td></tr>"+"<tr><td></td></tr>"+
                                    "</table>"+
                                "</div>"+

                                "<div style=\"padding: 0 5px 5px 5px;\">"+
                                    "<input type=\"button\" value=\"确定\" id=\"ok\" style=\"background: " + obj.themeColor + "; color:#FFFFFF; border: 1px solid " + obj.themeColor + "; margin:0 5px 0 0;\">"+
                                    "<input type=\"button\" value=\"取消\" id=\"cancel\" style=\"background: " + obj.themeColor + "    ; color:#FFFFFF; border: 1px solid " + obj.themeColor + ";\">"+
                                "</div>"+
                            "</div>"
                    );
                }
                if (obj.type == "alert") {
                    compnet = $(
                            "<div class=\"drag\" style=\"outline: 1px " + obj.themeColor + " solid;background: #FFFFFF; cursor:pointer; box-shadow: 10px 10px 5px #888888; text-align: center;width: 180px; height: auto; margin: 10px; position: fixed;\">"+
                            "<div style=\"background: " + obj.themeColor + "; color: #FFFFFF; text-align: left; padding: 0 0 2px 5px;\">提示信息"+
                                "<label title=\"关闭\" id=\"close\" style=\"float: right; background: url(‘image/close.png‘) no-repeat;\">&nbsp;&nbsp;&nbsp;</label>"+
                            "</div>"+

                            "<div style=\"padding: 5px;background: url(‘image/pm.gif‘) no-repeat;background-position:left top;\">"+
                                "<table style=\"padding:20px 0 0 0; font-size:12px; table-layout: fixed; border: 1px solid " + obj.themeColor + ";text-align: center; width: 100%;word-break: break-all;word-wrap:break-word;\">"+
                                    "<tr><td>" + content + "</td></tr>"+"<tr><td></td></tr>"+
                                "</table>"+
                            "</div>"+

                            "<div style=\"padding: 0 5px 5px 5px;\">"+
                                "<input type=\"button\" value=\"确定\" id=\"ok\" style=\"background: " + obj.themeColor + "; color:#FFFFFF; border: 1px solid " + obj.themeColor + "; margin:0 5px 0 0;\">"+
                            "</div>"+
                        "</div>"
                    );
                }

                $(compnet).css({"top":"200px","left":"500px"});// 初始化显示位置
                var move=false;//移动标记
                var _x = 0,_y = 0;//鼠标离控件左上角的相对位置, left:0, top:0初始化为左上角, js的局部变量可以不用初始化;
                $(compnet).mousedown(function(e){
                    move=true;
                    _x=e.pageX - $(compnet).position().left;
                    _y=e.pageY - $(compnet).position().top;
                });
                $(compnet).mouseout(function(e){// 当鼠标指针从元素上移开时,发生 mouseout 事件。
                    if(move){
                        var x=e.pageX-_x;//控件左上角到屏幕左上角的相对位置
                        var y=e.pageY-_y;
                        $(compnet).css({"top":y,"left":x});
                        /* 拖拽时取消文字选中 start*/
                        if(window.getSelection){
                            window.getSelection().removeAllRanges(); //w3c
                        }else  if(document.selection){
                            document.selection.empty();//IE
                        }
                        /* 拖拽时取消文字选中 finish*/
                    }
                }).mouseup(function(){
                move=false;
                });

                // close
                var close = compnet.children("div").find("label[id*=close]");
                  close.on("click", function(){
                    compnet.hide();
                    setTimeout(function(){
                        compnet.show();
                    }, 1000*5);
                });

                  if (this.booleanFactory(isOpen).key) {// 如果设置了confrimModal(true)模式显示坐标信息;
                      $("body").mousemove(function(e){
                          compnet.children("div").find("table tr td:eq(1)").html("X axis: " + e.pageX + " | Y axis: " + e.pageY + " <br> width: " + $(".drag").width() + " | height: " + $(".drag").height());
                    });
                }

                  if (obj.type == "info") {
                      var i = 5;
                    var intervalid;
                    intervalid = setInterval(function(){
                        if (i == 1) {
                            //window.location.href = "../index.html";
                            window.location.reload();
                            clearInterval(intervalid);
                        }
                        compnet.children("div").find("table tr td:eq(1)").html("<font style=\"color:#FF0000;\">" + i + "</font> 秒后自动消失!");
                        i--;
                    }, 1000); 

                }

                return $(this).append(compnet);// 返回组件对象, 可以继续使用jQuery的链式操作;
            }
        });
    })(jQuery);

OK, 大功告成!

时间: 2024-08-05 03:26:08

用jQuery写了一个模态框插件感觉挺好看的在博客园分享一下!的相关文章

用jQuery写了一个模态框插件

用jQuery写了一个模态框插件 大家觉得下面的框框好看么, 水印可以去掉(这个任务交给你们了(- o -)~zZ); "info"框 $("div").confrimModal("<font color=\"green\">成功! </font>", {type:"info", themeColor: "#008B8B"}, true); "alert

发现一个骗粉丝的人后发现博客园的一个bug

发现一个骗粉丝的人后发现博客园的一个bug 当你点开这篇文章的时候,如果你已经登录博客园账号,那么你自动回成为我的博客园粉丝,因为我加了自动关注的js,这里并不是想骗粉丝,希望博客园能重视这个bug(当然博客园肯定知道这个bug的).明天早上我会删除掉这段js的. 起因>发现一个骗粉丝的人 经过>他是如何实现骗粉丝的 我的一些思考 1.发现一个骗粉丝的人 今天下班,打开博客园的时候看到这篇文章,点了进去,感觉排版不错,自定义的界面体验非常不错,职业性地点击了主页看了看,发现了一个问题,于是乎有

第二百四十三节,Bootstrap模态框插件

Bootstrap模态框插件 学习要点: 1.基本使用 2.用法说明 本节课我们主要学习一下 Bootstrap 中的模态框插件,这是一款交互式网站非常常见的 弹窗功能插件. 一.基本使用 使用模态框的弹窗组件需要三层 div 容器元素: 1分别为 modal(模态声明层). 2dialog(窗口声明层). 3content(内容层). 在内容层里面,还有三层: 1分别为 header(头 部). 2body(主体). 3footer(注脚). modal样式class类,写在声明模态框<div

第 13 章 模态框插件

学习要点: 1.基本使用 2.用法说明 主讲教师:李炎恢 本节课我们主要学习一下 Bootstrap 中的模态框插件, 这是一款交互式网站非常常见的弹窗功能插件. 一.基本使用 使用模态框的弹窗组件需要三层 div 容器元素,分别为 modal(模态声明层). dialog(窗口声明层).content(内容层).在内容层里面,还有三层,分别为 header(头部).body(主体).footer(注脚). //基本实例 <!-- 模态声明,show 表示显示 --><div class

原生js写的一个弧形菜单插件

弧形菜单是一种半弧式或者全弧形菜单,是一种不同于传统横向或者竖向菜单形式的菜单.最近在网上看到好多人写出了这种效果,于是也尝试自己写了一个. 实现方式:原生态js 主要结构: 1.参数合并 1 var defaultPra = { 2 mainMenuId: "ArcMenu",//主菜单id 3 menuBoxId:"menuBox",//菜单包裹id 4 position: "",//弧形菜单 5 customPosition:"0

轻量级Modal模态框插件cta.js

今天给大家分享一款轻量级Modal模态框插件cta.js.这是一款无需使用jQuery插件,纯js编写的模态框弹出特效.效果图如下: 在线预览   源码下载 实现的代码. html代码: <section class="section--white" style="margin-top: 40px;"> <div class="tile-container"> <div class="tile"

多功能万能模态框插件,项目实用,持续更新中...

附github地址 https://github.com/pomelott/jquery-plug-in 模态框(modelBox) 使用方法 1.引入css文件(建议复制粘贴至项目css文件中) 2.引入js文件(建议使用发布的压缩版,需引入jquery) 3.创建模态框对象,并传入参数. 参数说明 num:0 *必填 模态框索引:自定义整形数字(创建多个模态框时用以区分) cover:true 是否显示遮罩层:ture(有),false(没有),默认为true pos:"center&quo

第一次来博客园先用jquery写一个简单菜单收缩效果

<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head>    <meta charset="utf-8" />    <title></title>    <script src="jquery-1.7.2.min.js"></script&g

CSS:仿写博客园写一个静态网页

要求:一个小时仿照博客园的格局,写一个静态的网页,主要采用HTML+CSS+DIV的布局方式, 新建两个文件:website.html.website.css website.html代码如下: <!doctype html> <html lang="zh-CN"> <head> <meta charset="ansi"> <media name="description" content=&