1 /***2 * Prompt提示语插件3 * 编写时间:2013年4月8号4 * version:Prompt.1.0.js5 * author:小宇<i@windyland.com>6 ***/
7 (function($){8 $.extend({9 PromptBox:{10 defaults : {11                     name  :    "T"+ newDate().getTime(),12                     content :"This is tips!",                            //弹出层的内容(text文本、容器ID名称、URL地址、Iframe的地址)
13                     width : 200,                                    //弹出层的宽度
14                     height : 70,15                     time:2000,//设置自动关闭时间,设置为0表示不自动关闭
16                     bg:true
17 },18 timer:{19                     stc:null,20                     clear:function(){21                         if(this.st)clearTimeout(this.st);22                         if(this.stc)clearTimeout(this.stc);23 }24 },25                 config:function(def){26                     this.defaults = $.extend(this.defaults,def);27 },28                 created:false,29                 create : function(op){30                     this.created=true;31                     var ops = $.extend({},this.defaults,op);32                     this.element = $("<div class='Prompt_floatBoxBg' id='fb"+ops.name+"'></div><div class='Prompt_floatBox' id='"+ops.name+"'><div class='content'></div></div>");33                     $("body").prepend(this.element);34                     this.blank = $("#fb"+ops.name);                        //遮罩层对象
35                     this.content = $("#"+ops.name+" .content");                //弹出层内容对象
36                     this.dialog = $("#"+ops.name+"");                        //弹出层对象
37                     if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {//判断IE6
38                         this.blank.css({height:$(document).height(),width:$(document).width()});39 }40 },41                 show:function(op){42                     this.dialog.show();43                     var ops = $.extend({},this.defaults,op);44                     this.content.css({width:ops.width});45                     this.content.html(ops.content);46                     var Ds ={47                                width:this.content.outerWidth(true),48                                height:this.content.outerHeight(true)49 };50                     if(ops.bg){51                         this.blank.show();52                         this.blank.animate({opacity:"0.5"},"normal");53                     }else{54                         this.blank.hide();55                         this.blank.css({opacity:"0"});56 }57                     this.dialog.css({58 width:Ds.width,59 height:Ds.height,60                                     left:(($(document).width())/2-(parseInt(Ds.width)/2)-5)+"px",61                                     top:(($(window).height()-parseInt(Ds.height))/2+$(document).scrollTop())+"px"
62 });63                     if ($.isNumeric(ops.time)&&ops.time>0){//自动关闭
64                         this.timer.clear();65                         this.timer.stc = setTimeout(function(){66                             var DB =$.PromptBox;67 DB.close();68 },ops.time);69 }70 },71                 close:function(){72                     var DB =$.PromptBox;73                         DB.blank.animate({opacity:"0.0"},74                                          "normal",75                                          function(){76 DB.blank.hide();77 DB.dialog.hide();78 });79 DB.timer.clear();80 }81 },82             Prompt:function(con,t,ops){83                 if(!$.PromptBox.created){$.PromptBox.create(ops);}84                 if($.isPlainObject(con)){85                     if(con.close){86 $.PromptBox.close();87                     }else{88 $.PromptBox.config(con);89 }90                     return true;91 }92                 ops =$.extend({},$.PromptBox.defaults,ops,{time:t});93                 ops.content = con||ops.content;94 $.PromptBox.show(ops);95 }96 })97 })(jQuery);

Prompt插件

jquery.prompt.js是一款基于jQuery的插件,只要是设置弹出层的效果包括登陆等。

1 /*弹出层插件样式开始*/
2 .Prompt_floatBoxBg{display:none;width:100%;height:100%;background:#000;position:fixed !important;/*ie7 ff*/position:absolute;top:0;left:0;filter:alpha(opacity=0);opacity:0; z-index:999;}3 .Prompt_floatBox{4 z-index:1000;5 display: block;6 position: absolute;7 padding:6px;8 text-align:center;9 top: 404.5px;10 left: 531.5px;11 height: auto;12 z-index: 10000;13 word-wrap: break-word;14 -webkit-box-shadow: rgba(0, 0, 0, 0.498039) 0px 0px 15px;15 box-shadow: rgba(0, 0, 0, 0.498039) 0px 0px 15px;16 border-top-left-radius: 6px;17 border-top-right-radius: 6px;18 border-bottom-right-radius: 6px;19 border-bottom-left-radius: 6px;20 background-color: white;21 opacity: 1;22 }23 .Prompt_floatBox .content{padding:10px;background:#fff;overflow-x:hidden;overflow-y: auto;}24 /*弹出层插件样式结束*/

这个样式在js里面调用css

这个CSS主要是通过弹框插件的js直接给通过加class的方式加上样式

演示代码:记得这个插件式依赖jquery的需要引入jquery.min.js文件

1 <script src="js/jquery-1.8.3.min.js" type="text/javascript"></script>
2 <script type="text/javascript" src="js/jquery.prompt.min.js"></script>
3 <script type="text/javascript">
4 $(document).ready(function(){5     $("a[pid]").click(function(){6         var pid = $(this).attr("pid");7         eval($("#"+pid).html());8 });9 });10 </script>
11 </head>
12 <body>
13 <br />
14 <br />
15 <br />
16 <center>
17 <div class="prompt_tmp">
18     <a class="a" pid="tmp1">直接按默认打开</a><br/>
19     <pre class="brush: jscript;" id="tmp1">$.Prompt();</pre>
20 </div>
21 <div class="prompt_tmp">
22     <a class="a" pid="tmp2">设置提示内容</a><br/>
23     <pre class="brush: jscript;" id="tmp2">$.Prompt("欢迎光临本站!");</pre>  //class="brush: jscript;"只是把代码语法高亮的显示出来,与pre搭配使用
24 </div>
25 <div class="prompt_tmp">
26     <a class="a" pid="tmp3">设置自动关闭时间为4s</a><br/>
27     <pre class="brush: jscript;" id="tmp3">$.Prompt("欢迎光临本站!4S",4000);</pre>
28 </div>
29 <div class="prompt_tmp">
30     <a class="a" pid="tmp4">设置自动关闭时间为100s,然后在2s后强制关闭</a><br/>
31     <pre class="brush: jscript;" id="tmp4">
32 $.Prompt("欢迎光临本站!2S",100000);33 setTimeout(function(){34     $.Prompt({close:true});35 },2000);36     </pre>
37 </div>
38 <div class="prompt_tmp">
39     <a class="a" pid="tmp5">修改默认参数后,不带参数打开</a><br/>
40     <pre class="brush: jscript;" id="tmp5">
41 var def ={42     content:"欢迎来到jq-school!",43     time:1000
44 }45 $.Prompt(def);46 $.Prompt();47     </pre>
48 </div>

参考:jq-school.com/Detail.aspx?id=227

补充说明:当使用jQuery1.8.3以上版本时可能出现弹框弹不出来的问题

QQ:1689986723

转载于:https://www.cnblogs.com/yuqiandoudou/p/4439179.html

jquery.prompt.js 弹窗的使用相关推荐

  1. cefsharp重写默认js弹窗(alert/confirm/prompt)

    1.设置js弹窗控制器 webView.JsDialogHandler = this;  //js弹窗控制 this表示本类对象,所以本类要实现IJsDialogHandler接口 2.实现IJsDi ...

  2. jquery、js父子页面操作总结

    jquery 父.子页面之间页面元素的获取,方法的调用 https://www.cnblogs.com/it-xcn/p/5896231.html 一.jquery 父.子页面之间页面元素的获取,方法 ...

  3. day05【JQuery框架】HTML引入Jquery、jQuery与JS区别、基本选择器、层级关系选择器、属性选择器、过滤选择器、 对象遍历、Jquery的DOM操作【重点】、Jquery事件绑定

    回顾 1. bom对象window对象三种弹框alert()confirm()prompt()二种定时器一次性:setTimout() --- 通过递归实现循环性循环性:setInterval()lo ...

  4. dialog.js弹窗插件

    从一开始使用alert来提示,到后来的jQuery手动写弹窗,再到后来使用layer弹窗插件来完成,到现在使用dialog插件来完成弹窗,一步步的摸索,一步步的收获. 现在在项目中大部分的弹窗都是使用 ...

  5. 报表生成(POI,jquery.table2excel.js,Echarts)

    最近公司要弄个报表相关的功能,话不多说,先上图 前一种是POI 生成的,后一种是Echarts生成的.报表我想大家都不陌生,基本上在公司业务中都会使用到.先说说POI,jquery.table2exc ...

  6. jQuery实现广告弹窗

    首先设置一个固定的窗口位于右下角,效果如下: 代码: jQuery实现广告弹窗.html 之后将该窗口初始设为隐藏,通过代码实现3秒自动显示,5秒自动隐藏,其效果如下: 1 <!DOCTYPE ...

  7. jQuery.validationEngine.js学习

    项目中使用到了这个插件,抽了个空,看了一下. (function($){ var method ={} $.fn.validationEngine = function(){} $.validatio ...

  8. 使用jquery.more.js来实现点击底部更多后, 底部加载出新的数据

    <div class="bus-nav-bar ft12"><div class="navt bor-r-c pos-rel {if $int == 0 ...

  9. jquery即时搜索查询插件jquery.search.js

    jquery.search.js搜索插件是一款基于jquery的插件,任何一个input输入款均可即时转为查询框,可分为前台数据直接显示和后台传输数据显示两种方案!  文档说明:http://www. ...

最新文章

  1. 分布式锁用 Redis 还是 Zookeeper?
  2. OVS vswitchd启动(三十六)
  3. 记录 之 tf.placeholder() 函数的意义及用法
  4. nginx服务器配置安全维护,Nginx服务器相关的一些安全配置建议
  5. c++ memset 语言_C/C++ 中memset() 函数详解及其作用介绍
  6. [转载] 第一个Python CGI编程和配置
  7. /dev/null脚本中作用
  8. 破解Excel受保护文件
  9. C语言或C++中不同类型指针所占内存大小
  10. STM32F103 CubeMX:ETR外部脉冲计数器
  11. 广告(文案)与营销(市场、传播和创意)
  12. DELL笔记本电脑电池不充电以及键盘失灵问题
  13. SQL执行顺序和流程
  14. nginx处理http请求
  15. 谷歌开放生成式AI Bard,百度文心一言《唐伯虎点秋香》出圈
  16. 关于linux磁盘爆满定位大文件的方法
  17. java基础题22:(单选题)在Java中,以下描述错误的是( )
  18. BLUEMOON记录
  19. 【游戏开发】《Java游戏服务器架构实战》项目在windows上部署
  20. 「Medical Image Analysis」Notes on Concurrent Spatial and Channel Squeeze Excitation

热门文章

  1. ubuntu16.04 kinetic外接Intel Realsense D435i配置教程
  2. JAVA最常用的排序_冒泡排序、选择排序、快速排序
  3. java 连接IBM MQ的方法和常见问题
  4. WebDriver高级应用实例(3)
  5. 关于启动一个线程监控队列的替代方案
  6. Python Day15 jQuery
  7. Hadoop学习之Combiner
  8. matlab 基本变量和函数
  9. 测试丢包_入行游戏测试之弱网测试工具
  10. 元宇宙突然大火,可是,到底什么是元宇宙呢?