栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

vue.js 实现评价五角星组件的实例代码

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

vue.js 实现评价五角星组件的实例代码

饿了么的五角星有三种形状,分别是实星,半星,空星

并且组件要能实现,这个五角星不同大小,评分也不一样,比如满分五颗星,四颗半星,四颗星等等....

所以需要像组件传入一个大小:size,一个分数:score

代码如下:


 
 
   @import "../../common/stylus/mixin.styl";
   .star
     font-size:0
     .star-item
display:inline-block
background-repeat:no-repeat
     &.star-48
.star-item
  width:20px
  height:20px
  margin-right:22px
  background-size:20px 20px
  &:last-child
    margin-right:0
  &.on
    bg-image('star48_on')
  &.half
    bg-image('star48_half')
  &.off
    bg-image('star48_off')
     &.star-36
.star-item
  width:15px
  height:15px
  margin-right:6px
  background-size:15px 15px
  &:last-child
    margin-right:0
  &.on
    bg-image('star36_on')
  &.half
    bg-image('star36_half')
  &.off
    bg-image('star36_off')
     &.star-24
.star-item
  width:10px
  height:10px
  margin-right:3px
  background-size:10px 10px
  &:last-child
    margin-right:0
  &.on
    bg-image('star24_on')
  &.half
    bg-image('star24_half')
  &.off
    bg-image('star24_off')  
 

其中:使用了size为48,36,24,所以我们需要图片3种类型的图片,并且要使用适应不同分辨率,要有@2x.png,@3x.png图片

对了,bg-image方法是在mixin.styl中的,代码如下

bg-image($url)
   background-image:url($url+"@2x.png")
   @media (-webkit-min-device-pixel-ratio:3),(min-device-pixel-ratio:3)
     background-image:url($url+"@3x.png")

组件的使用就很简单了

总结

以上所述是小编给大家介绍的vue.js 实现评价五角星组件的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/79952.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号