这篇文章主要介绍jQuery如何实现弹出窗口,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
今天讲了Jquery的弹出窗口的组成和用法:
先把引用文件的代码写好:
// 每个弹窗的标识 var x =0; var idzt = new Array(); var Window = function(config){ //ID不重复 idzt[x] = "zhuti"+x; //弹窗ID //初始化,接收参数 this.config = { width : config.width || 300, //宽度 height : config.height || 200, //高度 buttons : config.buttons || '', //默认无按钮 title : config.title || '标题', //标题 content : config.content || '内容', //内容 isMask : config.isMask == false?false:config.isMask || true, //是否遮罩 isDrag : config.isDrag == false?false:config.isDrag || true, //是否移动 }; //加载弹出窗口 var w = ($(window).width()-this.config.width)/2; var h = ($(window).height()-this.config.height)/2; var nr = "
这个JS文件把弹出窗口的内容,样式,位置,按钮,以及遮罩层都做了处理,在引用前好好看看里面的代码,最好都能弄懂,里面也做了详细的注释,希望可以帮的你。
下面是CSS样式表:
.zhuti { position:absolute; z-index:3; font-size:14px; border-radius:5px; box-shadow:0 0 5px white; overflow:hidden; color:#333; } .title { background-color:#3498db; vertical-align:middle; height:35px; width:100%; line-height:35px; text-indent:1em; } .close{ float:right; width:35px; height:35px; font-weight:bold; line-height:35px; vertical-align:middle; color:white; font-size:18px; } .close:hover { cursor:pointer; } .content { text-indent:1em; padding-top:10px; } .btnx { height:30px; width:100%; text-indent:1em; } .btn { height:28px; width:80px; float:left; margin-left:20px; color:#333; } #zz { width:100%; height:100%; opacity:0.15; display:none; background-color:#ccc; z-index:2; position:absolute; top:0px; left:0px; }
这个样式表把每个标签和所需要的样式都写好了,这样就能节省主要页面的代码量,并且让主页面看起来非常的整齐,如果要改,只需要在CSS样式表中修改即可,注意:不管要引用什么文件,必须把Jquery文件放在最前面!!!
下面是主页面代码:
无标题文档