index.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>lime-circle</title>
  8. <style>
  9. html,
  10. body {
  11. padding: 0;
  12. margin: 0;
  13. width: 100%;
  14. height: 100%;
  15. }
  16. .l-circle {
  17. position: relative;
  18. width: 100%;
  19. height: 100%;
  20. }
  21. .l-circle__trail,
  22. .l-circle__stroke {
  23. position: absolute;
  24. width: 100%;
  25. height: 100%;
  26. border-radius: 50%;
  27. }
  28. .l-circle__inner {
  29. position: absolute;
  30. left: 0;
  31. right: 0;
  32. top: 0;
  33. bottom: 0;
  34. align-items: center;
  35. justify-content: center;
  36. display: flex;
  37. }
  38. .is-round .l-circle__trail .cap {
  39. position: absolute;
  40. display: block;
  41. width: var(--l-trail-cap-size, 6px);
  42. height: var(--l-trail-cap-size, 6px);
  43. background-color: var(--l-trail-cap-color, #ddd);
  44. z-index: 10;
  45. border-radius: 50%;
  46. }
  47. .is-round .l-circle__trail .cap.start {
  48. left: var(--l-trail-cap-start-x, 14%);
  49. top: var(--l-trail-cap-start-y, 81%);
  50. }
  51. .is-round .l-circle__trail .cap.end {
  52. left: var(--l-trail-cap-end-x, 14%);
  53. top: var(--l-trail-cap-end-y, 81%);
  54. }
  55. .is-round .l-circle__stroke .cap {
  56. position: absolute;
  57. display: block;
  58. width: var(--l-stroke-cap-size, 6px);
  59. height: var(--l-stroke-cap-size, 6px);
  60. background-color: var(--l-stroke-cap-start-color, #ddd);
  61. border-radius: 50%;
  62. transition: opacity 350ms ease-out;
  63. opacity: var(--l-stroke-cap-opacity, 0);
  64. }
  65. .is-round .l-circle__stroke .cap.start {
  66. left: var(--l-stroke-cap-start-x, 14%);
  67. top: var(--l-stroke-cap-start-y, 81%);
  68. background-color: var(--l-stroke-cap-start-color, #ddd);
  69. }
  70. .is-round .l-circle__stroke .cap.end {
  71. left: var(--l-stroke-cap-end-x, 14%);
  72. top: var(--l-stroke-cap-end-y, 81%);
  73. z-index: -1;
  74. background-color: var(--l-stroke-cap-end-color, #ddd);
  75. }
  76. .clockwise .l-circle__inner {
  77. transform: scale(-1, 1);
  78. }
  79. </style>
  80. </head>
  81. <body>
  82. <canvas id="limeCanvas" class="l-circle"></canvas>
  83. <div id="limeCss" class="l-circle">
  84. <div class="l-circle__trail">
  85. <i class="cap start"></i>
  86. <i class="cap end"></i>
  87. </div>
  88. <div class="l-circle__stroke">
  89. <i class="cap start"></i>
  90. <i class="cap end"></i>
  91. </div>
  92. </div>
  93. <script type="text/javascript" src="./uni.webview.1.5.3.js"></script>
  94. <script type="text/javascript" src="./circle.min.js"></script>
  95. <script>
  96. const useCanvas = !CSS.supports('background', 'conic-gradient(#000, #fff)');
  97. const canvas = document.querySelector('#limeCanvas');
  98. const css = document.querySelector('#limeCss');
  99. let circle = null
  100. function toStyle(obj) {
  101. let str = ''
  102. for (const key in obj) {
  103. str += `${key}:${obj[key]};`
  104. }
  105. return str
  106. }
  107. function setStyle(type, style) {
  108. if (!type) {
  109. const trail = document.querySelector('.l-circle__trail')
  110. trail.style = toStyle(style)
  111. } else {
  112. const stroke = document.querySelector('.l-circle__stroke')
  113. stroke.style = toStyle(style)
  114. }
  115. // trail.style.background = 'red'
  116. // trail.setAttribute()
  117. // trail.style.setProperty('--color','#cd0000');
  118. }
  119. // type 0删除 1增加
  120. function setClass(target, className, type) {
  121. const box = document.querySelector(target);
  122. if (!type) {
  123. box.classList.remove(className)
  124. } else {
  125. box.classList.add(className)
  126. }
  127. }
  128. function postMessage(data) {
  129. uni.postMessage({
  130. data
  131. });
  132. };
  133. function emit(event, data) {
  134. postMessage({
  135. event,
  136. data
  137. });
  138. };
  139. function setOption(data) {
  140. if (circle) circle.setOption(data)
  141. }
  142. function clear() {
  143. if (circle) circle.clear()
  144. }
  145. function play(v) {
  146. if (circle) circle.play(v)
  147. }
  148. function stop() {
  149. if (circle) circle.stop()
  150. }
  151. function dispose() {
  152. if (circle) circle.dispose()
  153. }
  154. if (useCanvas) {
  155. css.remove()
  156. circle = new lime.Circle(canvas, {
  157. pixelRatio: window.devicePixelRatio,
  158. run: (current) => {
  159. emit('progress', current);
  160. }
  161. })
  162. } else {
  163. canvas.remove()
  164. setStyle(0, {
  165. "mask": "radial-gradient(transparent 65.5px, #000 66px)",
  166. "-webkit-mask": "radial-gradient(transparent 65.5px, #000 66px)",
  167. "background": "conic-gradient(from 225deg, #ddd 0%, #ddd 75%, transparent 75%, transparent 100%)",
  168. "--l-trail-cap-start-x": "20.209632098128225px",
  169. "--l-trail-cap-start-y": "117.79036790187178px",
  170. "--l-trail-cap-end-x": "117.79036790187178px",
  171. "--l-trail-cap-end-y": "117.79036790187178px",
  172. "--l-trail-cap-color": "#ddd",
  173. "--l-trail-cap-size": "6px"
  174. })
  175. setStyle(1, {
  176. "mask": "radial-gradient(transparent 57.5px, #000 58px)",
  177. "-webkit-mask": "radial-gradient(transparent 57.5px, #000 58px)",
  178. "background": "conic-gradient( transparent 0%, #2db7f5 0%, #2db7f5 var(--l-circle-percent), transparent var(--l-circle-percent), transparent 100%)",
  179. "--l-circle-percent": "0%",
  180. "--l-circle-stroke-cap-start-color": "#2db7f5",
  181. "--l-circle-stroke-cap-end-color": "#2db7f5",
  182. "--l-circle-stroke-cap-start-x": "61.00000000000001px",
  183. "--l-circle-stroke-cap-start-y": "0px",
  184. "--l-circle-stroke-cap-end-x": "0",
  185. "--l-circle-stroke-cap-end-y": "0",
  186. "--l-circle-stroke-cap-size": "6px",
  187. "--l-circle-stroke-cap-opacity": 0
  188. })
  189. }
  190. emit('init', {
  191. useCanvas
  192. })
  193. </script>
  194. </body>
  195. </html>