首页 > 语言 > JavaScript > 正文

javascript弹出窗口实现代码

2024-05-06 16:25:00
字体:
来源:转载
供稿:网友

这篇文章主要介绍了javascript弹出窗口实现代码,非常人性化的设计,点击页面可以弹出窗口,感兴趣的小伙伴们可以参考一下

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

 

 
  1. <!DOCTYPE html> 
  2. <html> 
  3. <head lang="en"
  4. <meta charset="UTF-8"
  5. <title>弹出窗口</title> 
  6. <script src="js/jquery-1.11.1.js"></script> 
  7. <style> 
  8. *{ 
  9. margin: 0; 
  10. padding: 0; 
  11. div{ 
  12. margin: 0 auto; 
  13. /*border: 1px solid red;*/ 
  14. .overBg{ 
  15. width: 100%; 
  16. height: 100%; 
  17. background: gray; 
  18. opacity: 0.5; 
  19. filter: alpha(opacity=50); 
  20. position: fixed; 
  21. top:0; 
  22. z-index: 300; 
  23. .tc-con{ 
  24. width: 200px; 
  25. height: 200px; 
  26. padding: 30px; 
  27. background: blanchedalmond; 
  28. position: fixed; 
  29. top: 0; 
  30. z-index: 1000; 
  31. </style> 
  32. <script> 
  33. $(function(){ 
  34. $('.tc').hide(); 
  35. $('.btn').click(function(){ 
  36. $('.tc').show(); 
  37. }) 
  38. $('.tc').click(function(){ 
  39. $(this).hide(); 
  40. }) 
  41. }) 
  42. </script> 
  43. </head> 
  44. <body> 
  45. <div class="btn">点击出现</div> 
  46. <div class="tc"
  47. <div class="overBg"></div> 
  48. <div class="tc-con" id="tc-con">22</div> 
  49. <script> 
  50. var a=document.getElementById('tc-con'); 
  51. a.style.left=(document.body.clientWidth/2- a.clientWidth/2)+'px'
  52. a.style.top=(document.documentElement.clientHeight/2- a.clientHeight/2)+'px'
  53. </script> 
  54. </div> 
  55. <div style="height:2000px">22</div> 
  56. </body> 
  57. </html><!DOCTYPE html> 
  58. <html> 
  59. <head lang="en"
  60. <meta charset="UTF-8"
  61. <title>弹出窗口</title> 
  62. <script src="js/jquery-1.11.1.js"></script> 
  63. <style> 
  64. *{ 
  65. margin: 0; 
  66. padding: 0; 
  67. div{ 
  68. margin: 0 auto; 
  69. /*border: 1px solid red;*/ 
  70. .overBg{ 
  71. width: 100%; 
  72. height: 100%; 
  73. background: gray; 
  74. opacity: 0.5; 
  75. filter: alpha(opacity=50); 
  76. position: fixed; 
  77. top:0; 
  78. z-index: 300; 
  79. .tc-con{ 
  80. width: 200px; 
  81. height: 200px; 
  82. padding: 30px; 
  83. background: blanchedalmond; 
  84. position: fixed; 
  85. top: 0; 
  86. z-index: 1000; 
  87. </style> 
  88. <script> 
  89. $(function(){ 
  90. $('.tc').hide(); 
  91. $('.btn').click(function(){ 
  92. $('.tc').show(); 
  93. }) 
  94. $('.tc').click(function(){ 
  95. $(this).hide(); 
  96. }) 
  97. }) 
  98. </script> 
  99. </head> 
  100. <body> 
  101. <div class="btn">点击出现</div> 
  102. <div class="tc"
  103. <div class="overBg"></div> 
  104. <div class="tc-con" id="tc-con">22</div> 
  105. <script> 
  106. var a=document.getElementById('tc-con'); 
  107. a.style.left=(document.body.clientWidth/2- a.clientWidth/2)+'px'
  108. a.style.top=(document.documentElement.clientHeight/2- a.clientHeight/2)+'px'
  109. </script> 
  110. </div> 
  111. <div style="height:2000px">22</div> 
  112. </body> 
  113. </html> 

效果图:

javascript弹出窗口实现代码

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


注:相关教程知识阅读请移步到JavaScript/Ajax教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选