jQuery和字体 简易星级评定系统真棒 Star Rating.js

  • 源码大小:7.23KB
  • 所需积分:1积分
  • 源码编号:19JP-3318
  • 浏览次数:545次
  • 最后更新:2023年05月30日
  • 所属栏目:其他
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

star-rating.js是一个简单、轻便、响应迅速、可定制、美观的星级评定系统,使用jQuery和Font Awesome 6标志性字体构建。

特征:

  • 自定义评级符号。
  • 自定义星形尺寸。
  • 允许指定星星的数量。
  • 自定义反馈消息。
  • 将评分值存储在隐藏的输入中。

如何使用它:

1.加载jquery.star-rating.jsjQuery库之后的JavaScript。

  1. <script src="/path/to/cdn/jquery.slim.min.js"></script>
  2. <script src="/path/to/jquery.star-rating.js"></script>

2.加载最新的Font Awesome Iconic Font for stars字体。通过覆盖图标选项,您可以使用任何其他图标库,甚至可以使用表情符号作为星号(参见下文)。

  1. <link rel="stylesheet" href="/path/to/cdn/font-awesome/all.min.css" />

3.创建一个DIV容器来容纳评级系统。

  1. <div class="rating"></div>

4.调用DIV容器上的函数来创建默认的五星评级系统。

  1. $('.rating').starRating({
  2. // ...
  3. });

5.定制星星。

  1. $('.rating').starRating({
  2. starIconEmpty: 'far fa-star',
  3. starIconFull: 'fas fa-star',
  4. starColorEmpty: 'lightgray',
  5. starColorFull: '#FFC107',
  6. starsSize: 4, // em
  7. stars: 5,
  8. });

6.自定义反馈消息。

  1. $('.rating').starRating({
  2. showInfo: true,
  3. titles: ["Very Bad", "Poorly", "Medium", "Good", "Excellent!"],
  4. });

7.自定义隐藏评级输入的名称。

  1. $('.rating').starRating({
  2. inputName: 'rating',
  3. });

8.当额定值发生变化时,触发一个功能。

  1. $(document).on('change', '.rating', function (e, stars, index) {
  2. alert(`Thx for ${stars} stars!`);
  3. });

更新日志:

2022-11-05

  • 请改用Font Awesome 6.x

预览截图