task-comp.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. .container {
  6. display: flex;
  7. height: 100%;
  8. }
  9. .left-panel {
  10. flex: 1;
  11. background-color: #f1f1f1;
  12. padding: 20px;
  13. }
  14. .right-panel {
  15. flex: 1;
  16. padding: 20px;
  17. }
  18. .calculator {
  19. max-width: 300px;
  20. margin: 0 auto;
  21. border: 1px solid #ccc;
  22. padding: 10px;
  23. }
  24. .output {
  25. background-color: #f1f1f1;
  26. text-align: right;
  27. padding: 10px;
  28. margin-bottom: 10px;
  29. }
  30. .buttons {
  31. display: grid;
  32. grid-template-columns: repeat(4, 1fr);
  33. gap: 10px;
  34. }
  35. button {
  36. padding: 10px;
  37. font-size: 16px;
  38. background-color: #3498db;
  39. color: #fff;
  40. border: none;
  41. cursor: pointer;
  42. transition: background-color 0.3s ease;
  43. }
  44. button:hover {
  45. background-color: #2980b9;
  46. }
  47. .loader-container {
  48. width: 100%;
  49. height: 100%;
  50. position: fixed;
  51. top: 0;
  52. left: 0;
  53. display: flex;
  54. align-items: center;
  55. justify-content: center;
  56. background-color: rgba(0, 0, 0, 0.5);
  57. visibility: hidden;
  58. opacity: 0;
  59. transition: visibility 0s, opacity 0.5s;
  60. }
  61. .loader {
  62. border: 16px solid #f3f3f3;
  63. border-top: 16px solid #3498db;
  64. border-radius: 50%;
  65. width: 120px;
  66. height: 120px;
  67. animation: spin 2s linear infinite;
  68. }
  69. @keyframes spin {
  70. 0% {
  71. transform: rotate(0deg);
  72. }
  73. 100% {
  74. transform: rotate(360deg);
  75. }
  76. }
  77. .loader-container.loading {
  78. visibility: visible;
  79. opacity: 1;
  80. }
  81. .button {
  82. display: inline-block;
  83. padding: 10px 20px;
  84. background-color: #3498db;
  85. color: #fff;
  86. border: none;
  87. cursor: pointer;
  88. transition: background-color 0.3s ease;
  89. }
  90. .button:hover {
  91. background-color: #2980b9;
  92. }
  93. .dropdown {
  94. position: relative;
  95. display: inline-block;
  96. margin-top: 10px;
  97. }
  98. .dropdown-content {
  99. display: none;
  100. position: absolute;
  101. background-color: #f9f9f9;
  102. min-width: 200px;
  103. box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  104. z-index: 1;
  105. }
  106. .dropdown:hover .dropdown-content {
  107. display: block;
  108. }
  109. .dropdown-item {
  110. padding: 10px;
  111. cursor: pointer;
  112. transition: background-color 0.3s ease;
  113. }
  114. .dropdown-item:hover {
  115. background-color: #ddd;
  116. }
  117. </style>
  118. <div class="container">
  119. <div class="left-panel">
  120. <button class="button" onclick="showInfo('按钮1被点击')">按钮1</button>
  121. <button class="button" onclick="showInfo('按钮2被点击')">按钮2</button>
  122. <button class="button" onclick="showInfo('按钮3被点击')">按钮3</button>
  123. <button class="button" onclick="showInfo('按钮4被点击')">按钮4</button>
  124. <button class="button" onclick="showInfo('按钮5被点击')">按钮5</button>
  125. <button class="button" onclick="showInfo('按钮6被点击')">按钮6</button>
  126. </div>
  127. <div class="right-panel">
  128. <div id="info"></div>
  129. <button class="interactive-button" onclick="showMessage()">交互按钮</button>
  130. <input type="text" id="input" placeholder="在这里输入文本">
  131. </div>
  132. </div>
  133. <script>
  134. function showInfo(text) {
  135. document.getElementById("info").textContent = text;
  136. }
  137. function showMessage() {
  138. var inputText = document.getElementById("input").value;
  139. alert(inputText);
  140. }
  141. </script>
  142. </head>
  143. <div class="container">
  144. <div class="left-panel">
  145. <button class="button" onclick="showInfo('按钮1被点击')">按钮1</button>
  146. <button class="button" onclick="showInfo('按钮2被点击')">按钮2</button>
  147. <button class="button" onclick="showInfo('按钮3被点击')">按钮3</button>
  148. <button class="button" onclick="showInfo('按钮4被点击')">按钮4</button>
  149. <button class="button" onclick="showInfo('按钮5被点击')">按钮5</button>
  150. <button class="button" onclick="showInfo('按钮6被点击')">按钮6</button>
  151. </div>
  152. <div class="right-panel">
  153. <div id="info"></div>
  154. <button class="interactive-button" onclick="showMessage()">交互按钮</button>
  155. <input type="text" id="input" placeholder="在这里输入文本">
  156. </div>
  157. </div>
  158. <script>
  159. function showInfo(text) {
  160. document.getElementById("info").textContent = text;
  161. }
  162. function showMessage() {
  163. var inputText = document.getElementById("input").value;
  164. alert(inputText);
  165. }
  166. </script>
  167. <body>
  168. <div class="calculator">
  169. <div class="output" id="output">0</div>
  170. <div class="buttons">
  171. <button onclick="appendNumber('7')">7</button>
  172. <button onclick="appendNumber('8')">8</button>
  173. <button onclick="appendNumber('9')">9</button>
  174. <button onclick="appendOperator('+')">+</button>
  175. <button onclick="appendNumber('4')">4</button>
  176. <button onclick="appendNumber('5')">5</button>
  177. <button onclick="appendNumber('6')">6</button>
  178. <button onclick="appendOperator('-')">-</button>
  179. <button onclick="appendNumber('1')">1</button>
  180. <button onclick="appendNumber('2')">2</button>
  181. <button onclick="appendNumber('3')">3</button>
  182. <button onclick="appendOperator('*')">*</button>
  183. <button onclick="appendNumber('0')">0</button>
  184. <button onclick="appendNumber('.')">.</button>
  185. <button onclick="calculate()">=</button>
  186. <button onclick="appendOperator('/')">/</button>
  187. <button onclick="clearExpression()">C</button>
  188. <button onclick="backspace()">&#9003;</button>
  189. </div>
  190. </div>
  191. <div class="loader-container" id="loaderContainer">
  192. <div class="loader"></div>
  193. </div>
  194. <div class="dropdown">
  195. <button class="button">按钮1</button>
  196. <div class="dropdown-content">
  197. <div class="dropdown-item">选项1</div>
  198. <div class="dropdown-item">选项2</div>
  199. <div class="dropdown-item">选项3</div>
  200. </div>
  201. </div>
  202. <div class="dropdown">
  203. <button class="button">按钮2</button>
  204. <div class="dropdown-content">
  205. <div class="dropdown-item">选项4</div>
  206. <div class="dropdown-item">选项5</div>
  207. <div class="dropdown-item">选项6</div>
  208. </div>
  209. </div>
  210. <div class="dropdown">
  211. <button class="button">按钮3</button>
  212. <div class="dropdown-content">
  213. <div class="dropdown-item">选项7</div>
  214. <div class="dropdown-item">选项8</div>
  215. <div class="dropdown-item">选项9</div>
  216. </div>
  217. </div>
  218. <div class="dropdown">
  219. <button class="button">按钮4</button>
  220. <div class="dropdown-content">
  221. <div class="dropdown-item">选项10</div>
  222. <div class="dropdown-item">选项11</div>
  223. <div class="dropdown-item">选项12</div>
  224. </div>
  225. </div>
  226. <script>
  227. var dropdowns = document.getElementsByClassName("dropdown");
  228. for (var i = 0; i < dropdowns.length; i++) {
  229. dropdowns[i].addEventListener("mouseover", function () {
  230. this.children[1].style.display = "block";
  231. });
  232. dropdowns[i].addEventListener("mouseout", function () {
  233. this.children[1].style.display = "none";
  234. });
  235. }
  236. </script>
  237. <script>
  238. let outputDiv = document.getElementById('output');
  239. let expression = '';
  240. function appendNumber(number) {
  241. if (expression === '0') {
  242. expression = '';
  243. }
  244. expression += number;
  245. outputDiv.innerText = expression;
  246. }
  247. function appendOperator(operator) {
  248. if (expression.slice(-1) === '+' || expression.slice(-1) === '-' || expression.slice(-1) === '*' || expression.slice(-1) === '/') {
  249. expression = expression.slice(0, -1);
  250. }
  251. expression += operator;
  252. outputDiv.innerText = expression;
  253. }
  254. function calculate() {
  255. try {
  256. const result = eval(expression);
  257. expression = result.toString();
  258. outputDiv.innerText = expression;
  259. } catch (error) {
  260. // 处理错误
  261. expression = '';
  262. outputDiv.innerText = 'Error';
  263. }
  264. }
  265. function clearExpression() {
  266. expression = '';
  267. outputDiv.innerText = '0';
  268. }
  269. function backspace() {
  270. if (expression === '' || expression === '0') {
  271. return;
  272. }
  273. if (expression.length === 1) {
  274. expression = '0';
  275. } else {
  276. expression = expression.slice(0, -1);
  277. }
  278. outputDiv.innerText = expression;
  279. }
  280. // CSS 加载进度提示效果
  281. window.addEventListener('load', function () {
  282. document.getElementById('loaderContainer').classList.remove('loading');
  283. });
  284. </script>
  285. </body>
  286. </html>