对于jquery弹出插件,想起自己刚学习js那会,在实习的时候做过一个,唉,做工太粗浅了。

点击看效果demo

(function($, window, document,undefined){  var dialogInfo = {message: 'this ia a message', // 消息内容style: 'info', // 弹窗类型time: 1000, // 显示时间model:false // 是否模态};$.gmNoticeWnd = function(opt) {var settings = $.extend({}, dialogInfo, opt),dialogHtml = "";dialogHtml += '<div class = "notice alert" style = "width:200px; height:200px;padding:0px">'+ "<div class = 'notice-head' style = 'height: 10px'>"+  "<button type = 'button' class = 'close' style = 'display: none'>×</button>"+ "</div>"+"<br>"+'<div style="text-align:center;margin-top:15px">'+'<img id = "alertType" src = "/notice.js/img/check.png" style="text-align:center">'+'</div>'+ "<div class = 'notice-body'>"+ "<p class='diap'>" + settings.message + "</p>"+ "</div>"+ '</div>';var modalDialog = "<div class = 'noticecover' id = 'coverId' style = 'position: absolute; top: 0; left: 0; width:100%; height:100%; z-index: 99;'>" +dialogHtml +"</div>";return (function setNotice() {var noticeStyle = settings.style;if (settings.model == false) {$("body").append(dialogHtml);$(".noticecover").css("background","#000000");} else {$("body").append(modalDialog);$("button").css("display","block");   };var $notice = $(".notice"),noticeTop = (document.documentElement.clientHeight / 2) - $notice.height(),noticeLeft = (document.documentElement.clientWidth / 2) - $notice.width() / 2;$notice.css({"position": "absolute","top": noticeTop,"left": noticeLeft,                      });switch (noticeStyle) {case 'error':$notice.addClass("alert-danger");$('#alertType').attr('src','/notice.js/img/cross.png');break;case 'normal':$notice.addClass("alert-success");$('#alertType').attr('src','/notice.js/img/check.png');break;case 'warning':$notice.addClass("alert-warning");break;default:$notice.addClass("alert-info");};setTimeout(function() {if (settings.model == false) {$notice.remove();} else {$(".close").click(function() {$(".noticecover").remove();});};   }, settings.time);function setPosition() {var fatherCover = document.getElementById("coverId"),changedLeft = $(fatherCover).width() / 2 - $notice.width() / 2,changedTop = $(fatherCover).height() / 2 - $notice.height() / 2;$notice.css({"position": "absolute","top": changedTop,"left": changedLeft,                        });}if (window.addEventListener) {window.addEventListener("resize", function() {setPosition();})} else if (window.attachEvent) {window.attachEvent("onresize", function() {setPosition();})}} ());      };$.fn.appearDialog = function(opt) {$.gmNoticeWnd(opt);};})(jQuery, window, document);

  以上是我自己的源码,仅仅能满足提示的需求。

var TINY = {};function T$(i) {return document.getElementById(i)
}TINY.box = function () {var p, m, b, fn, ic, iu, iw, ih, ia, f = 0;return {show: function (c, u, w, h, a, t) {if (!f) {p = document.createElement('div');p.id = 'tinybox';m = document.createElement('div');m.id = 'tinymask';b = document.createElement('div');b.id = 'tinycontent';document.body.appendChild(m);document.body.appendChild(p);p.appendChild(b);m.onclick = TINY.box.hide;window.onresize = TINY.box.resize;f = 1}if (!a && !u) {p.style.width = w ? w + 'px' : 'auto';p.style.height = h ? h + 'px' : 'auto';p.style.backgroundImage = 'none';b.innerHTML = c} else {b.style.display = 'none';p.style.width = p.style.height = '100px'}this.mask();ic = c;iu = u;iw = w;ih = h;ia = a;this.alpha(m, 1, 80, 3);if (t) {setTimeout(function () {TINY.box.hide()}, 1000 * t)}},fill: function (c, u, w, h, a) {if (u) {p.style.backgroundImage = '';var x = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');x.onreadystatechange = function () {if (x.readyState == 4 && x.status == 200) {TINY.box.psh(x.responseText, w, h, a)}};x.open('GET', c, 1);x.send(null)} else {this.psh(c, w, h, a)}},psh: function (c, w, h, a) {if (a) {if (!w || !h) {var x = p.style.width,y = p.style.height;b.innerHTML = c;p.style.width = w ? w + 'px' : '';p.style.height = h ? h + 'px' : '';b.style.display = '';w = parseInt(b.offsetWidth);h = parseInt(b.offsetHeight);b.style.display = 'none';p.style.width = x;p.style.height = y;} else {b.innerHTML = c}this.size(p, w, h, 4)} else {p.style.backgroundImage = 'none'}},hide: function () {TINY.box.alpha(p, -1, 0, 5)},resize: function () {TINY.box.pos();TINY.box.mask()},mask: function () {m.style.height = TINY.page.theight() + 'px';m.style.width = '';m.style.width = TINY.page.twidth() + 'px'},pos: function () {var t = (TINY.page.height() / 2) - (p.offsetHeight / 2);t = t < 10 ? 10 : t;p.style.top = (t + TINY.page.top()) + 'px';p.style.left = (TINY.page.width() / 2) - (p.offsetWidth / 2) + 'px'},alpha: function (e, d, a, s) {clearInterval(e.ai);if (d == 1) {e.style.opacity = 0;e.style.filter = 'alpha(opacity=0)';e.style.display = 'block';this.pos()}e.ai = setInterval(function () {TINY.box.twalpha(e, a, d, s)}, 20)},twalpha: function (e, a, d, s) {var o = Math.round(e.style.opacity * 100);if (o == a) {clearInterval(e.ai);if (d == -1) {e.style.display = 'none';e == p ? TINY.box.alpha(m, -1, 0, 3) : b.innerHTML = p.style.backgroundImage = ''} else {e == m ? this.alpha(p, 1, 100, 5) : TINY.box.fill(ic, iu, iw, ih, ia)}} else {var n = o + Math.ceil(Math.abs(a - o) / s) * d;e.style.opacity = n / 100;e.style.filter = 'alpha(opacity=' + n + ')'}},size: function (e, w, h, s) {e = typeof e == 'object' ? e : T$(e);clearInterval(e.si);var ow = e.offsetWidth,oh = e.offsetHeight,wo = ow - parseInt(e.style.width),ho = oh - parseInt(e.style.height);var wd = ow - wo > w ? -1 : 1,hd = (oh - ho > h) ? -1 : 1;e.si = setInterval(function () {TINY.box.twsize(e, w, wo, wd, h, ho, hd, s)}, 20)},twsize: function (e, w, wo, wd, h, ho, hd, s) {var ow = e.offsetWidth - wo,oh = e.offsetHeight - ho;if (ow == w && oh == h) {clearInterval(e.si);p.style.backgroundImage = 'none';b.style.display = 'block'} else {if (ow != w) {e.style.width = ow + (Math.ceil(Math.abs(w - ow) / s) * wd) + 'px'}if (oh != h) {e.style.height = oh + (Math.ceil(Math.abs(h - oh) / s) * hd) + 'px'}this.pos()}}}
}();TINY.page = function () {return {top: function () {return document.body.scrollTop || document.documentElement.scrollTop},width: function () {return self.innerWidth || document.documentElement.clientWidth},height: function () {return self.innerHeight || document.documentElement.clientHeight},theight: function () {var d = document,b = d.body,e = d.documentElement;return Math.max(Math.max(b.scrollHeight, e.scrollHeight), Math.max(b.clientHeight, e.clientHeight))},twidth: function () {var d = document,b = d.body,e = d.documentElement;return Math.max(Math.max(b.scrollWidth, e.scrollWidth), Math.max(b.clientWidth, e.clientWidth))}}
}();

  这个是别人做的一个弹出插件,写的比我好太多了。值得学习。也不依赖于jquery。

<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery实现弹出层效果</title>
<style type="text/css">.title{background:#eeeeee; border:1px solid #cccccc; padding:1em;margin-bottom: 25px;}.content{padding:1em;}#tinybox{position:absolute; display:none; padding:10px; background:#ffffff url(../image/preload.gif) no-repeat 50% 50%; border:10px solid #e3e3e3; z-index:2000;}#tinymask{position:absolute; display:none; top:0; left:0; height:100%; width:100%; background:#000000; z-index:1500;}#tinycontent{background:#ffffff; font-size:1.1em;}
</style>
<script type="text/javascript" src="../js/tinybox.js"></script>
</head>
<body><div class="title"><b>加载一个静态页面</b><a title="加载一个静态页面,这里可能无法测试出来,在服务器项目里可以看见效果"   href="# " id="click_test1">效果预览</a></div><div class="title"><b>图片</b><a title="用酷酷的浮动层显示图片"   href="# " id="click_test2">效果预览</a></div><div class="title"><b>显示flash</b><a title="用酷酷的浮动层显示flash"   href="# " id="click_test3">效果预览</a></div><div class="title"><b>自动隐藏</b><a title="层显示一段时间后自动隐藏,当作操作提示用是个很不错的选择"  href="# " id="click_test4">效果预览</a></div><script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script><script type="text/javascript">$('#click_test1').click(function(e) {TINY.box.show('blank-for-test.html', 1, 300, 150, 1);});var content2 = "<img width='640' height='466' src='../../pic&wordLineInMiddle/images/img4.jpg' />";$('#click_test2').click(function(e) {TINY.box.show(content2, 0, 0, 0, 1);});var content3 = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='550' height='400'><param name='movie' value='../flash/as3_clock_2.swf' /><param name='quality' value='high' /><param name='wmode' value='opaque' /><embed height='400' width='550'  src='../flash/as3_clock_2.swf' type='application/x-shockwave-flash'></embed></object>";$('#click_test3').click(function(e) {TINY.box.show(content3, 0, 0, 0, 1);});var content4 = "该浮动层将在3秒钟内消失。";$('#click_test4').click(function(e) {TINY.box.show(content4, 0, 0, 0, 0, 3);});</script>
</body>
</html>

  附上自己的demo用例

转载于:https://www.cnblogs.com/lemon-zhang/p/7985931.html

jquery弹出插件相关推荐

  1. jQuery弹出插件thickbox使用心得

    thickbox是一个简单易用的jQuery插件. 其官网:http://jquery.com/demo/thickbox/ .上面有源码和示例.一般只要在需要添加弹出窗体的元素中加上它的类thick ...

  2. html 弹出层插件,jQuery弹出层插件(原创)

    插件描述:简约的jQuery弹出层插件 更新时间:2020-01-17 23:37:28 更新说明:版本v4.3.0 1.修复最大化可拖动.改变大小的问题 2.去除对于图片的依赖 3.更新拖动插件 4 ...

  3. jbox弹窗_强大的jquery弹出层插件jBox

    jBox是一款功能强大的jquery弹出层插件.jBox插件可以用来创建tooltips提示框.模态窗口.图片画廊等多种效果. 使用方法 在页面中引入jBox.all.min.css.jquery和j ...

  4. Jquery 弹出对话框插件xcConfirm.js

    Jquery 弹出对话框插件xcConfirm.js,感觉很方便使用,使用方法如下: <!DOCTYPE html> <html><head><meta ch ...

  5. 实用的 jquery 弹出窗口 插件winbox

    实用的 jquery 弹出窗口 插件winbox 一个基于jQuery的弹出层.支持拖拽,支持内容为文字,图片,URL等!至于兼容性.在IE6下,弹出对像无法绝对固定.其他应该没啥大问题: 应用演示: ...

  6. 40个有创意的jQuery图片和内容滑动及弹出插件收藏集之二

    <40个有创意的jQuery图片和内容滑动及弹出插件收藏集之一> <40个有创意的jQuery图片和内容滑动及弹出插件收藏集之三> <40个有创意的jQuery图片和内容 ...

  7. Jquery弹出层插件ThickBox的使用方法

    这篇文章主要介绍了Jquery弹出层插件ThickBox的使用方法,需要的朋友可以参考下 thickbox是jQuery的一个插件,其作用是弹出对话框.网页框,使用户体验度更加愉悦,下面就来简单介绍它 ...

  8. jquery 弹出窗口_jQuery弹出窗口和工具提示窗口动画效果

    jquery 弹出窗口 In this tutorial, we are going to discuss about a jQuery plugin for responsive and acces ...

  9. 弹框位置设置html,JQuery弹出框定位实现方法

    JQuery弹出框定位实现方法.直接上代码: //页面代码 (简化) CssClass="ui-button-icons-only" Text="按钮"> ...

最新文章

  1. android studio val,Kotlin学习笔记之const val与val
  2. java xml 拆分_java – 如何使用VTDGenHuge将大型xml拆分成小块?
  3. 让Maven项目使用Nexus作为远程仓库的settings.xml配置
  4. Kotlin 学习笔记01
  5. [vue] 为何官方推荐使用axios而不用vue-resource?
  6. 直播App测试重点问题 - 服务器压力
  7. glibc版本查看_[译] 写一个简单的内存分配器(替换glibc中的malloc函数)
  8. Sublime Text 插件-全栈开发收集
  9. Atitit 算法之道 之压缩算法 attilax总结 1. 压缩算法与压缩格式区别 1 2. 压缩算法于格式 1 2.1. H264 mpg jpg MP3 2 2.2. Zip rar 。L
  10. 江苏事业单位计算机类考申论吗,笔试将近!2020年江苏事业单位统考你要注意!...
  11. 显卡驱动程序如何更新
  12. 个人作业4 结对开发地铁
  13. Matlab的fprintf函数使用百分号问题
  14. Java爬虫之批量下载LibreStock图片(可输入关键词查询下载)
  15. 多线程应用_左圆右方
  16. Centos 下使用speedtest-cli 进行测速
  17. 在Fragment中使用Listview
  18. CDR智能填充—图形颜色填充好帮手
  19. 谷歌翻译用不了,失效的最新解决方法之一
  20. BFU C.yi的书包 01背包【水题】

热门文章

  1. stm32 带通滤波器_带通滤波 - 基于STM32芯片和TFT-LCD的便携式心电图仪设计
  2. rtsp协议_基于libVLC的视频播放器(支持RTSP协议)
  3. linux mysql 文件恢复_linux下误删数据文件恢复
  4. java地图点线面_openlayers之点,线,面(以城市,河流,省份为例,分别对应点线面)...
  5. python里的符号区别_Python中的方括号和点符号有什么区别?
  6. 计算机右键管理显示没权限,解决右键 选择打开方式提示没有权限
  7. 计算机基础知识专插本,计算机基础专插本复习资料.doc
  8. el table 固定表头和首行_el-table表头根据内容自适应,解决表头错位和固定列错位(完美解决)...
  9. 测试用例优先级划分_全面的质量保障体系之测试用例分级
  10. postman 字符数组_PostMan Post方式传递数组数据参数 OK_go-Go语言中文社区