index.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <title>评分组件</title>
  2. <div class="layui-card layadmin-header">
  3. <div class="layui-breadcrumb" lay-filter="breadcrumb">
  4. <a lay-href="">主页</a>
  5. <a><cite>组件</cite></a>
  6. <a><cite>评分组件</cite></a>
  7. </div>
  8. </div>
  9. <div class="layui-fluid">
  10. <div class="layui-row layui-col-space15">
  11. <div class="layui-col-md6">
  12. <div class="layui-card">
  13. <div class="layui-card-header">基础效果</div>
  14. <div class="layui-card-body">
  15. <div id="test-rate-dome1"></div>
  16. </div>
  17. </div>
  18. <div class="layui-card">
  19. <div class="layui-card-header">显示文字</div>
  20. <div class="layui-card-body">
  21. <div id="test-rate-dome2"></div>
  22. </div>
  23. </div>
  24. <div class="layui-card">
  25. <div class="layui-card-header">半星效果</div>
  26. <div class="layui-card-body">
  27. <div id="test-rate-dome3"></div>
  28. <div><div id="test-rate-dome4"></div></div>
  29. </div>
  30. </div>
  31. <div class="layui-card">
  32. <div class="layui-card-header">自定义主题色</div>
  33. <div class="layui-card-body">
  34. <ul>
  35. <li><div id="test-rate-dome10"></div></li>
  36. <li><div id="test-rate-dome11"></div></li>
  37. <li><div id="test-rate-dome12"></div></li>
  38. <li><div id="test-rate-dome13"></div></li>
  39. <li><div id="test-rate-dome14"></div></li>
  40. </ul>
  41. </div>
  42. </div>
  43. </div>
  44. <div class="layui-col-md6">
  45. <div class="layui-card">
  46. <div class="layui-card-header">只读</div>
  47. <div class="layui-card-body">
  48. <div id="test-rate-dome9"></div>
  49. </div>
  50. </div>
  51. <div class="layui-card">
  52. <div class="layui-card-header">自定义内容</div>
  53. <div class="layui-card-body">
  54. <div id="test-rate-dome5"></div>
  55. <div><div id="test-rate-dome6"></div></div>
  56. </div>
  57. </div>
  58. <div class="layui-card">
  59. <div class="layui-card-header">自定义长度</div>
  60. <div class="layui-card-body">
  61. <div id="test-rate-dome7"></div>
  62. <div><div id="test-rate-dome8"></div></div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. <script>
  69. layui.use(['admin', 'rate'], function(){
  70. var rate = layui.rate;
  71. //基础效果
  72. rate.render({
  73. elem: '#test-rate-dome1'
  74. })
  75. //显示文字
  76. rate.render({
  77. elem: '#test-rate-dome2'
  78. ,value: 2 //初始值
  79. ,text: true //开启文本
  80. });
  81. //半星效果
  82. rate.render({
  83. elem: '#test-rate-dome3'
  84. ,value: 2.5 //初始值
  85. ,half: true //开启半星
  86. })
  87. rate.render({
  88. elem: '#test-rate-dome4'
  89. ,value: 3.5
  90. ,half: true
  91. ,text: true
  92. })
  93. //自定义文本
  94. rate.render({
  95. elem: '#test-rate-dome5'
  96. ,value: 3
  97. ,text: true
  98. ,setText: function(value){ //自定义文本的回调
  99. var arrs = {
  100. '1': '极差'
  101. ,'2': '差'
  102. ,'3': '中等'
  103. ,'4': '好'
  104. ,'5': '极好'
  105. };
  106. this.span.text(arrs[value] || ( value + "星"));
  107. }
  108. })
  109. rate.render({
  110. elem: '#test-rate-dome6'
  111. ,value: 1.5
  112. ,half: true
  113. ,text: true
  114. ,setText: function(value){
  115. this.span.text(value);
  116. }
  117. })
  118. //自定义长度
  119. rate.render({
  120. elem: '#test-rate-dome7'
  121. ,length: 3
  122. });
  123. rate.render({
  124. elem: '#test-rate-dome8'
  125. ,length: 10
  126. ,value: 8 //初始值
  127. });
  128. //只读
  129. rate.render({
  130. elem: '#test-rate-dome9'
  131. ,value: 4
  132. ,readonly: true
  133. });
  134. //主题色
  135. rate.render({
  136. elem: '#test-rate-dome10'
  137. ,value: 3
  138. ,theme: '#FF8000' //自定义主题色
  139. });
  140. rate.render({
  141. elem: '#test-rate-dome11'
  142. ,value: 3
  143. ,theme: '#009688'
  144. });
  145. rate.render({
  146. elem: '#test-rate-dome12'
  147. ,value: 2.5
  148. ,half: true
  149. ,theme: '#1E9FFF'
  150. })
  151. rate.render({
  152. elem: '#test-rate-dome13'
  153. ,value: 2.5
  154. ,half: true
  155. ,theme: '#2F4056'
  156. });
  157. rate.render({
  158. elem: '#test-rate-dome14'
  159. ,value: 2.5
  160. ,half: true
  161. ,theme: '#FE0000'
  162. })
  163. });
  164. </script>