button.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. /* 父容器基础样式 */
  6. .bottom-panel {
  7. position: fixed;
  8. bottom: 0;
  9. left: 0;
  10. width: 100%;
  11. height: 30vh;
  12. background: rgba(255, 255, 255, 0.95);
  13. box-shadow: 0 -2px 15px rgba(0, 0, 0, 0.1);
  14. /* 隐藏状态 */
  15. opacity: 0;
  16. visibility: hidden;
  17. /* 过渡动画 */
  18. transition: all 0.3s ease-in-out;
  19. /* Flex布局设置 */
  20. display: flex;
  21. flex-direction: column;
  22. justify-content: space-around;
  23. align-items: center;
  24. }
  25. /* 激活状态 */
  26. .bottom-panel.active {
  27. opacity: 1;
  28. visibility: visible;
  29. }
  30. /* 子元素样式 */
  31. .panel-item {
  32. width: 80%;
  33. height: 20%;
  34. min-height: 50px;
  35. background: #f8f9fa;
  36. border-radius: 8px;
  37. padding: 12px;
  38. transition: transform 0.2s;
  39. /* 内容居中 */
  40. display: flex;
  41. justify-content: center;
  42. align-items: center;
  43. font-family: Arial;
  44. }
  45. /* 交互效果 */
  46. .panel-item:hover {
  47. transform: translateY(-2px);
  48. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  49. }
  50. /* 触发按钮样式 */
  51. .trigger-btn {
  52. position: fixed;
  53. bottom: 20px;
  54. right: 20px;
  55. padding: 12px 24px;
  56. background: #007bff;
  57. color: white;
  58. border: none;
  59. border-radius: 25px;
  60. cursor: pointer;
  61. transition: all 0.2s;
  62. }
  63. .trigger-btn:hover {
  64. background: #0056b3;
  65. transform: scale(1.05);
  66. }
  67. </style>
  68. </head>
  69. <body>
  70. <!-- 触发按钮 -->
  71. <button class="trigger-btn">显示面板</button>
  72. <!-- 底部面板 -->
  73. <div class="bottom-panel">
  74. <div class="panel-item">内容区块 1</div>
  75. <div class="panel-item">内容区块 2</div>
  76. <div class="panel-item">内容区块 3</div>
  77. </div>
  78. <script>
  79. // 获取DOM元素
  80. const panel = document.querySelector('.bottom-panel');
  81. const triggerBtn = document.querySelector('.trigger-btn');
  82. // 点击触发按钮
  83. triggerBtn.addEventListener('click', () => {
  84. panel.classList.toggle('active');
  85. // 更新按钮文字
  86. const isActive = panel.classList.contains('active');
  87. triggerBtn.textContent = isActive ? '隐藏面板' : '显示面板';
  88. });
  89. // 点击面板外部关闭(可选)
  90. document.addEventListener('click', (e) => {
  91. if (!panel.contains(e.target) && e.target !== triggerBtn) {
  92. panel.classList.remove('active');
  93. triggerBtn.textContent = '显示面板';
  94. }
  95. });
  96. </script>
  97. </body>
  98. </html>