如何使用Awesome字体代替jQuery Rating Star中的图像

Shabarinath Volam

我正在使用jquery.raty.min.js来显示星级,在js方法中,我可以选择更改显示开始图像,例如

starOff:"/images/star_none.png",

starOn:"/images/star_full.png"

但是在这里我想使用字体真棒类

<i class="fa fa-star-o"></i>
<i class="fa fa-star"></i>

我已经尝试过像下面这样的课程

starOff:"<i class='fa fa-star-o'></i>",

starOn:"<i class='fa fa-star'></i>"

但任何人都无法帮助您做到这一点。

乔纳森

这个问题的简短答案是使用Raty(2.7.0)的最新更新(截至对此响应的最后编辑),并查看'starType'属性。设置元素时,您将执行以下操作:

$('div').raty({
  // This is the config you need to change the tag from image to icon
  starType : 'i'
});

这里有更多详细信息...如果您查看CSS文件和字体文件,您将看到它们如何设置<i>标记以使用特定字体。从那里开始,一个简单的任务就是确定每个班级的:before内容。首先确保包括FontAwesome,然后像这样配置CSS(特定于FontAwesome):

.cancel-on-png, .cancel-off-png, .star-on-png, .star-off-png, .star-half-png {
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;

  /*This is the important part*/
  font-family: "FontAwesome";

  font-style: normal;
  font-variant: normal;
  font-weight: normal;
  line-height: 1;
  speak: none;
  text-transform: none;
}

.cancel-on-png:before {
  /*the "\f057" represents an unfilled circle with an x in it*/
  /*each of these can be configured to be whichever icon you would like*/
  /*fore more information on the icon code, look at the link listed below*/
  content: "\f057";
}

.cancel-off-png:before {
  content: "\f05c";
}

.star-on-png:before {
  content: "\f005";
}

.star-off-png:before {
  content: "\f006";
}

.star-half-png:before {
  content: "\f123";
}

可在此处找到FontAwesome的CSS内容值的完整列表。


最终产品看起来像这样:

<div>
  <i title="Cancel this rating!" class="raty-cancel cancel-off-png" data-alt="x"></i>&nbsp;
  <i data-alt="1" class="star-off-png" title="Bad"></i>&nbsp;
  <i data-alt="2" class="star-off-png" title="Below Average"></i>&nbsp;
  <i data-alt="3" class="star-off-png" title="Average"></i>&nbsp;
  <i data-alt="4" class="star-off-png" title="Above Average"></i>&nbsp;
  <i data-alt="5" class="star-off-png" title="Great"></i>
  <input name="score" type="hidden">
</div>

当像这样配置时:

$(div).raty({
  readOnly    : readOnly,
  cancel      : !readOnly,
  noRatedMsg  : 'This component has not been rated yet',
  half        : true,
  starType    : 'i',
  hints       : ['Bad', 'Below Average', 'Average', 'Above Average', 'Great'],
  click       : function(score, event) {
    console.log("The score is:", score);
  }
});

我知道已经过去了3个月,但我希望这对某人有帮助!

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How to fill the first two stars in font awesome star rating?

来自分类Dev

jQuery Star Rating插件变量未正确返回

来自分类Dev

Rails 5 Star Rating jQuery Plugin Raty 没有通过评级值

来自分类Dev

rating bar not show all star in single row

来自分类Dev

如何使用vuetify v-rating事件?

来自分类Dev

赞成/反对使用Rating类的评级实施

来自分类Dev

如何在Primefaces DataTable中使用Font Awesome(或其他字体图标)代替jQuery Sprite?

来自分类Dev

如何快速接受RateController的Rating值作为字符串

来自分类Dev

如何更改星星的颜色以获取 p-rating

来自分类Dev

给定 <user, movie, rating> 我如何使用 Scala 为每个用户打印出评分最高的电影?

来自分类Dev

从使用star导入的模块中获取属性

来自分类Dev

使用Font Awesome更改WPF中的字体图标

来自分类Dev

使用Font Awesome更改WPF中的字体图标

来自分类Dev

将ASP.NET Rating控件值放置在FormView控件中时设置

来自分类Dev

将ASP.NET Rating控件值放置在FormView控件中时设置

来自分类Dev

使用ng-class附加CSS时uib-rating不变色

来自分类Dev

使用图像代替Java中的Rectangle?

来自分类Dev

如何使用 jQuery 更改网格中的图像?

来自分类Dev

如何使用字体-很棒的加载图像

来自分类Dev

我的代码中是否有某些内容阻止<div class =“ rating”>水平移动到屏幕中心附近?

来自分类Dev

如何在Star Basic中检查损坏的内部链接?

来自分类Dev

Star Micronics 使用 SDK 或 Socket for web 在 php 中打印

来自分类Dev

无法将NULL插入(“ STUDENT”。“ RATING”。“ RATING_AGENCY_ID”)

来自分类Dev

如何在jQuery mobile 1.4.0中使用自定义字体?

来自分类Dev

如何使用jQuery动态更改表格单元格中的字体

来自分类Dev

Set minimum rating for bonds in R

来自分类Dev

更改PrimeFaces p:rating的图标?

来自分类Dev

如何从webpack中的font-awesome-webpack配置字体文件输出目录?

来自分类Dev

如何在CakePHP提交按钮中插入Awesome字体字形/图标?

Related 相关文章

  1. 1

    How to fill the first two stars in font awesome star rating?

  2. 2

    jQuery Star Rating插件变量未正确返回

  3. 3

    Rails 5 Star Rating jQuery Plugin Raty 没有通过评级值

  4. 4

    rating bar not show all star in single row

  5. 5

    如何使用vuetify v-rating事件?

  6. 6

    赞成/反对使用Rating类的评级实施

  7. 7

    如何在Primefaces DataTable中使用Font Awesome(或其他字体图标)代替jQuery Sprite?

  8. 8

    如何快速接受RateController的Rating值作为字符串

  9. 9

    如何更改星星的颜色以获取 p-rating

  10. 10

    给定 <user, movie, rating> 我如何使用 Scala 为每个用户打印出评分最高的电影?

  11. 11

    从使用star导入的模块中获取属性

  12. 12

    使用Font Awesome更改WPF中的字体图标

  13. 13

    使用Font Awesome更改WPF中的字体图标

  14. 14

    将ASP.NET Rating控件值放置在FormView控件中时设置

  15. 15

    将ASP.NET Rating控件值放置在FormView控件中时设置

  16. 16

    使用ng-class附加CSS时uib-rating不变色

  17. 17

    使用图像代替Java中的Rectangle?

  18. 18

    如何使用 jQuery 更改网格中的图像?

  19. 19

    如何使用字体-很棒的加载图像

  20. 20

    我的代码中是否有某些内容阻止<div class =“ rating”>水平移动到屏幕中心附近?

  21. 21

    如何在Star Basic中检查损坏的内部链接?

  22. 22

    Star Micronics 使用 SDK 或 Socket for web 在 php 中打印

  23. 23

    无法将NULL插入(“ STUDENT”。“ RATING”。“ RATING_AGENCY_ID”)

  24. 24

    如何在jQuery mobile 1.4.0中使用自定义字体?

  25. 25

    如何使用jQuery动态更改表格单元格中的字体

  26. 26

    Set minimum rating for bonds in R

  27. 27

    更改PrimeFaces p:rating的图标?

  28. 28

    如何从webpack中的font-awesome-webpack配置字体文件输出目录?

  29. 29

    如何在CakePHP提交按钮中插入Awesome字体字形/图标?

热门标签

归档