1. 程式人生 > >jquery彈出框

jquery彈出框

pos AD hid doctype play pan start nbsp position

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>jQuery - Start Animation</title>
  5. <script type="text/javascript" src="../scripts/jquery-1.3.2-vsdoc2.js" ></script>
  6. <script type="text/javascript">
  7. $(document).ready(function()
  8. {
  9. //動畫速度
  10. var speed = 500;
  11. //綁定事件處理
  12. $("#btnShow").click(function(event)
  13. {
  14. //取消事件冒泡
  15. event.stopPropagation();
  16. //設置彈出層位置
  17. var offset = $(event.target).offset();
  18. $("#divPop").css({ top: offset.top + $(event.target).height() + "px", left: offset.left });
  19. //動畫顯示
  20. $("#divPop").show(speed);
  21. });
  22. //單擊空白區域隱藏彈出層
  23. $(document).click(function(event) { $("#divPop").hide(speed) });
  24. //單擊彈出層則自身隱藏
  25. $("#divPop").click(function(event) { $("#divPop").hide(speed) });
  26. });
  27. </script>
  28. </head>
  29. <body>
  30. <div>
  31. <br /><br /><br />
  32. <button id="btnShow">顯示提示文字</button>
  33. </div>
  34. <!-- 彈出層 -->
  35. <div id="divPop" style="background-color: #f0f0f0; border: solid 1px #000000; position: absolute; display:none;
  36. width: 300px; height: 100px;">
  37. <div style="text-align: center;" >彈出層</div>
  38. </div>
  39. </body>
  40. </html>

jquery彈出框