<h1>rating()</h1>
<p>Download and use : <a target='_blank' href='http://www.aycan.net/jquery-rating-uygulamasi/'>http://www.aycan.net/jquery-rating-uygulamasi/   </a> </p>
<div class="rating">
    <a href="#">1</a>
    <a href="#">2</a>
    <a href="#">3</a>
    <a href="#">4</a>
    <a href="#">5</a>
    <a href="#">6</a>
    <a href="#">7</a>
    <a href="#">8</a>
    <a href="#">9</a>
    <a href="#">10</a>
</div><!-- /. rating -->
<div style='clear:both;'></div>
<div class='callback'></div>
.rating{padding: 10px;}
    .rating a{width: 60px; height: 60px; background: url('http://calismalar.aycan.net/rating/stars.png') left top no-repeat; display: inline-block;  text-indent: -9999px; margin: 0 0;}
    .rating a.selected,
    .rating a.hover{background-position: right top; transform: scale(1.1); transition: transform ease-in-out .2s;}
            .callback{padding: 20px; font-size:20px;}
rating(function (e)
{
    $('.callback').html('Selected : 1-' + e);
});

function rating(callback)
{
    $('.rating a').on(
    {
        mouseover : function () {
            $(this).parent().find('a:lt(' + ($(this).index() + 1) + ')').addClass('hover');
        },
        mouseout : function () {
            $('.rating  a').removeClass('hover');
        },
        click : function ()
        {
            if($('.rating a').hasClass('selected'))
            {
                // Alert
                $('.rating a').removeClass('selected');
            } 

                $(this).parent().find('a:lt(' + ($(this).index() + 1) + ')').addClass('selected').removeClass('hover');
            typeof callback === 'function' && callback.call( this, ($(this).index() + 1) );
        }
    });
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. //cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js