dtkl55257 2017-04-20 18:54
浏览 37
已采纳

它们如何代表普通电影对imdb,烂番茄的评级?

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:

    1. A row of gold stars
    2. A row of gray stars

    Then, with a simple image mask you can calculate in js the relative width of the golden star layer.

    In greater detail, they actually use a sprite as the very basis:

    enter image description here

    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 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab