Created
September 20, 2016 13:40
-
-
Save artygrand/c86c51ca612cc0095d122c05a6cd9850 to your computer and use it in GitHub Desktop.
Simple stars vote script for input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
$('.stars').each(function(){ | |
var input = $(this), stars = $('<div class="stars-visible"><span></span><span></span><span></span><span></span><span></span></div>') | |
stars.find('span').click(function(){ | |
$(this).addClass('active').siblings().removeClass('active') | |
input.val(5-$(this).index()) | |
}) | |
input.hide().before(stars) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.stars-visible { | |
unicode-bidi: bidi-override; | |
direction: rtl; | |
width: 130px; | |
} | |
.stars-visible span { | |
display: inline-block; | |
width: 26px; | |
height: 26px; | |
background: url(img/star-off.png); | |
cursor: pointer; | |
} | |
.stars-visible span:hover, | |
.stars-visible span.active, | |
.stars-visible span:hover ~ span, | |
.stars-visible span.active ~ span { | |
background: url(img/star-on.png); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="number" name="stars" class="stars form-control"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment