index.html 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>测报灯网页</title>
  6. <style>
  7. html{
  8. --color-top-right: #ff005e;
  9. --color-bottom-left: #00d0ff;
  10. }
  11. html,body{margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;}
  12. body{ background: linear-gradient(-135deg, var(--color-top-right), var(--color-bottom-left));
  13. bottom: 0;
  14. left: 0;
  15. position: fixed;
  16. right: 0;
  17. top: 0;
  18. transition: opacity 600ms;
  19. }
  20. canvas{display: block;
  21. /* background-color: #333; */
  22. }
  23. button{
  24. background: rgba(0,0,0,.3); color: #00d0ff; border: 0; cursor: pointer; width: 80px; height: 36px; line-height: 36px; border-radius: 5px;
  25. }
  26. button.active{background: rgba(255, 255, 82, 0.5); color: #000;}
  27. </style>
  28. </head>
  29. <body>
  30. <div id="canvas-container" style="width: 100%; height: 100%;"></div>
  31. <div style="position: fixed; bottom: 2em; left: 50%; margin-left: -124px; ">
  32. <button id="el_light">开灯</button>
  33. <button id="el_size">显示尺寸</button>
  34. <button id="el_rotate">旋转</button>
  35. </div>
  36. </body>
  37. <script>
  38. window.baseURL = './'
  39. </script>
  40. <script type="module">
  41. import {openLight,closeLight,showSize,hideSize,autoRotate} from "./assets/js/index.js";
  42. let isOpenLight = false //开灯状态
  43. let isShowSize = false //显示尺寸
  44. let isRotate = true //是否旋转
  45. function lightToggle(e){
  46. if(isOpenLight) {
  47. isOpenLight = false
  48. closeLight();
  49. e.srcElement.innerText = '开灯'
  50. e.srcElement.classList.remove('active')
  51. } else {
  52. isOpenLight = true
  53. openLight();
  54. e.srcElement.innerText = '关灯'
  55. e.srcElement.classList.add('active')
  56. }
  57. }
  58. function sizeToggle(e){
  59. if(isShowSize) {
  60. isShowSize = false
  61. hideSize();
  62. e.srcElement.innerText = '显示尺寸'
  63. e.srcElement.classList.remove('active')
  64. } else {
  65. isShowSize = true
  66. showSize();
  67. e.srcElement.innerText = '隐藏尺寸'
  68. e.srcElement.classList.add('active')
  69. }
  70. }
  71. function rotateToggle(e){
  72. isRotate = !isRotate
  73. autoRotate(isRotate);
  74. if(isRotate) {
  75. e.srcElement.innerText = '旋转'
  76. e.srcElement.classList.remove('active')
  77. } else {
  78. e.srcElement.innerText = '停止旋转'
  79. e.srcElement.classList.add('active')
  80. }
  81. }
  82. document.getElementById('el_light').addEventListener('click', lightToggle);
  83. document.getElementById('el_size').addEventListener('click', sizeToggle);
  84. document.getElementById('el_rotate').addEventListener('click', rotateToggle);
  85. </script>
  86. </html>