手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >javascript弹出窗口实现代码
javascript弹出窗口实现代码
摘要:很多网页都实现了弹出窗口,使用方面,特别的人性化,本文就大家介绍javascript实现弹出窗口特效,具体代码如下:弹出窗口*{margin...

很多网页都实现了弹出窗口,使用方面,特别的人性化,本文就大家介绍javascript实现弹出窗口特效,具体代码如下:

<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>弹出窗口</title> <script src="js/jquery-1.11.1.js"></script> <style> *{ margin: 0; padding: 0; } div{ margin: 0 auto; /*border: 1px solid red;*/ } .overBg{ width: 100%; height: 100%; background: gray; opacity: 0.5; filter: alpha(opacity=50); position: fixed; top:0; z-index: 300; } .tc-con{ width: 200px; height: 200px; padding: 30px; background: blanchedalmond; position: fixed; top: 0; z-index: 1000; } </style> <script> $(function(){ $('.tc').hide(); $('.btn').click(function(){ $('.tc').show(); }) $('.tc').click(function(){ $(this).hide(); }) }) </script> </head> <body> <div>点击出现</div> <div> <div></div> <div id="tc-con">22</div> <script> var a=document.getElementById('tc-con'); a.style.left=(document.body.clientWidth/2- a.clientWidth/2)+'px'; a.style.top=(document.documentElement.clientHeight/2- a.clientHeight/2)+'px'; </script> </div> <div>22</div> </body> </html><!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>弹出窗口</title> <script src="js/jquery-1.11.1.js"></script> <style> *{ margin: 0; padding: 0; } div{ margin: 0 auto; /*border: 1px solid red;*/ } .overBg{ width: 100%; height: 100%; background: gray; opacity: 0.5; filter: alpha(opacity=50); position: fixed; top:0; z-index: 300; } .tc-con{ width: 200px; height: 200px; padding: 30px; background: blanchedalmond; position: fixed; top: 0; z-index: 1000; } </style> <script> $(function(){ $('.tc').hide(); $('.btn').click(function(){ $('.tc').show(); }) $('.tc').click(function(){ $(this).hide(); }) }) </script> </head> <body> <div>点击出现</div> <div> <div></div> <div id="tc-con">22</div> <script> var a=document.getElementById('tc-con'); a.style.left=(document.body.clientWidth/2- a.clientWidth/2)+'px'; a.style.top=(document.documentElement.clientHeight/2- a.clientHeight/2)+'px'; </script> </div> <div>22</div> </body> </html>

效果图:

javascript弹出窗口实现代码1

以上就是为大家分享的javascript弹出窗口实现代码,希望对大家的学习有所帮助。

【javascript弹出窗口实现代码】相关文章:

javascript的 {} 语句块详解

让插入到 innerHTML 中的 script 跑起来的实现代码

javascript实现查找数组中最大值方法汇总

javascript使用Promise对象实现异步编程

javascript瀑布流式图片懒加载实例

浅析javascript函数表达式

Javascript类型转换的规则实例解析

基于JavaScript实现图片点击弹出窗口而不是保存

JavaScript实现表格点击排序的方法

javascript函数特点实例

精品推荐
分类导航