Sha*_*lam 8 javascript css jquery raty
我正在使用jquery.raty.min.js来显示星级,在js方法中我可以选择更改显示开始图像
starOff:"/images/star_none.png",
starOn:"/images/star_full.png"
Run Code Online (Sandbox Code Playgroud)
但在这里我想使用字体真棒类
<i class="fa fa-star-o"></i>
<i class="fa fa-star"></i>
Run Code Online (Sandbox Code Playgroud)
我尝试过如下课程
starOff:"<i class='fa fa-star-o'></i>",
starOn:"<i class='fa fa-star'></i>"
Run Code Online (Sandbox Code Playgroud)
但它没有用,任何人都可以帮助这样做.
Jon*_*han 12
这个问题的简短回答是使用Raty的最新更新(2.7.0)(截至本回复的最后一次编辑)并查看'starType'属性.当您设置元素时,您将执行以下操作:
$('div').raty({
// This is the config you need to change the tag from image to icon
starType : 'i'
});
Run Code Online (Sandbox Code Playgroud)
这里有一些更详细的信息......如果您查看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";
}
Run Code Online (Sandbox Code Playgroud)
可以在此处找到FontAwesome的CSS内容值的完整列表
最终产品看起来像这样:
<div>
<i title="Cancel this rating!" class="raty-cancel cancel-off-png" data-alt="x"></i>
<i data-alt="1" class="star-off-png" title="Bad"></i>
<i data-alt="2" class="star-off-png" title="Below Average"></i>
<i data-alt="3" class="star-off-png" title="Average"></i>
<i data-alt="4" class="star-off-png" title="Above Average"></i>
<i data-alt="5" class="star-off-png" title="Great"></i>
<input name="score" type="hidden">
</div>
Run Code Online (Sandbox Code Playgroud)
配置如下:
$(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);
}
});
Run Code Online (Sandbox Code Playgroud)
我知道已经3个月了,但我希望这可以帮助别人!