Alright lets say the average rating of a movie/restaurant is 4.3. On the show page you have the name of the object, the description, the contact, images etc etc... then you have the average rating represented in stars. In the object's model you store the rating from every user and with simple mathematical formula you calculate the average. But what I am curious about is how do they represent 4.3 which is 4 stars and a little bit less than 4.5? Isn't it too much to have stored 50 png images? Thanks in advance.
1条回答 默认 最新
- doufu9947 2017-04-20 18:59关注
It's actually much simpler than it seems. Imagine two elements, stacked on top of one another:
- A row of gold stars
- A row of gray stars
Then, with a simple image mask you can calculate in
js
the relative width of thegolden star
layer.In greater detail, they actually use a sprite as the very basis:
Play with the width values and you'll see the full effect:
document.querySelector(".one .gold").style.width = "83.5%"; document.querySelector(".two .gold").style.width = "56%";
div{position:relative;height:12px;margin-bottom:10px;width: 140px; background:url('http://ia.media-imdb.com/images/G/01/imdb/images/rating/rating-list/sprite-1445387679._V_.png')0 -28px; } span{ position: absolute; top: 0; left: 0; height: 12px; background-image: url('http://ia.media-imdb.com/images/G/01/imdb/images/rating/rating-list/sprite-1445387679._V_.png'); } .gold{background-position: 0 -42px;}
<div class="one"> <span class="gold"></span> </div> <div class="two"> <span class="gold"></span> </div>
</div>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 quartus II 9.0闪退问题怎么解决啊,急
- ¥20 求自动化运维语料数据集
- ¥30 广告检测流量作弊案例 IDEA运行代码报错 连接不上metastore 检测了环境配置没有问题 请求远程解决加VX问细节问题 不加的不回复
- ¥15 matlab图像融合代码被嫌弃太简单,求改进。第一步改成直接读取三张图片,不读取文件夹
- ¥20 微处理器原理与应用(私有偿)
- ¥50 8051单片机关于ADC0809的应用
- ¥15 有没有能拿来练练手写完发给我
- ¥15 禁止修改windows系统时间
- ¥50 kinect连接win11笔电导致音视频设备消失
- ¥15 python线性查找题