Note that there are some explanatory texts on larger screens.

plurals
  1. PORating system and CSS sprites
    primarykey
    data
    text
    <p>I have implemented three star rating system based on popularity count in my website, but now my client wants to change colors of those three stars (default blue) to red, blue and green which shows the (degree of) popularity.</p> <p>I've implemented this star rating system using CSS sprites, where I included two star images - golden and gray, in one sprite and displaying these using some logic. Works fine for one color, but how to implement three colours for each star?</p> <p>HTML</p> <pre><code>&lt;div class="star-box"&gt; &lt;li&gt; &lt;span class="stars"&gt;&lt;?php echo $position;?&gt;&lt;/span&gt; &lt;/li&gt; &lt;/div&gt; </code></pre> <p>PHP</p> <pre><code>if( !isset($_SESSION['ranking']) || $_SESSION['ranking']['points'] &lt;= 1000 ) { if( !isset($_SESSION['ranking']['points']) || $_SESSION['ranking']['points'] == '' ) { $position = '0px'; $position = 0.00; } else { $position = ($_SESSION['ranking']['points'] * 0.14).'px'; $position = 0.75; } $str1 = 'class="active" '; $str1 .= ' style="background-position:'.$position.' 9px;"'; } if( $_SESSION['ranking']['points'] &gt; 1000 &amp;&amp; $_SESSION['ranking']['points'] &lt;= 5000 ) { if( !isset($_SESSION['ranking']['points']) || $_SESSION['ranking']['points'] == '' ) { $position = '0px'; $position = 0.00; } else { $position = ($_SESSION['ranking']['points']*0.035).'px'; $position = 1.40; } } </code></pre> <p>jQuery</p> <pre><code>$(function() { $('span.stars').stars(); }); $.fn.stars = function() { return $(this).each(function() { // get the value var val = parseFloat($(this).html()); // make sure that the value is in (0 - 5) range, multiply to get width val = Math.round(val * 4) / 4; var size = Math.max(0, (Math.min(5, val))) * 16; // create stars holder var $span = $('&lt;span /&gt;').width(size); // replace the numerical value with stars $(this).html($span); }); } </code></pre> <p>CSS</p> <pre><code>span.stars, span.stars span { display: block; background: url(../../images/stars.png) 0 -16px repeat-x; width: 50px; height: 20px; text-indent: -9999px; } span.stars span { background-position: 0 0; } </code></pre> <p>SPRITE IMAGE :</p> <p><img src="https://i.stack.imgur.com/HaXy8.png" alt=""></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload