Reputation: 25
Im following a tutorial on this page: http://www.henryhoffman.com/css-star-rating-tutorial.html where the HTML looks like this:
<ul class="rating">
<li><a href="#" title="1 Star">1</a></li>
<li><a href="#" title="2 Stars">2</a></li>
<li><a href="#" title="3 Stars">3</a></li>
<li><a href="#" title="4 Stars">4</a></li>
<li><a href="#" title="5 Stars">5</a></li>
</ul>
And the CSS like this:
ul.rating{
background:url(../img/site_img/star.jpg) bottom;
height:21px;
width:115px;
overflow:hidden;
}
ul.rating li{
display:inline
}
.rating a {
display:block;
width:23px;
height:21px;
float:left;
text-indent:-9999px;
position:relative;
}
.rating a:hover {
background:url(../img/site_img/star.jpg) center;
width:115px;
margin-left:-92px;
position:static;
}
.rating a:active {
background-position:top;
}
My problem is that I dont want an a href, I don't want to be transferd to another possition on the page. I just want the the value (1, 2, 3, 4 or 5) to be stored in a label so I can pass that value to the database when I press a button. And if I choose three stars I want three stars to be colured after a pressed the stars and dont hoover the stars anymore.
How can I do that?
Upvotes: 2
Views: 2183
Reputation: 1410
This i similar, should get you on the right track. There are a couple of functions I do not include here, however the base is there for you to work with.
here is the fiddle: http://jsfiddle.net/n76My/5/
var index=1;
$(".beeRating li").on({
mouseover: function() {
if(index==1)
{
$(this).addClass('stop');
$("li").each(function(index,domEle) {
$(domEle).css('opacity', '1');
if( $(this).hasClass('stop') ) {
return false;
}
})
}
},
mouseleave: function() {
if(index==1)
{
$(this).removeClass('stop');
$("li").each(function(index,domEle) {
$(domEle).css('opacity', '.25');
})
}
},
click: function() {
var rating = $(this).attr('id');
console.log(rating);
index=0;
$.ajax({ // do ajax request
url: "/echo/json/"
}).done(function() {
alert("success");
index=1; // on done set the index as 1
});
}
});
Upvotes: 0
Reputation: 67194
I think you can just change your a hrefs
into spans, seeing as the CSS already declared a display:block
this should work. Also in CSS change rating a
to rating span
See if that helps.
<ul class="rating">
<li><span>1</span></li>...
.rating span {
display:block;...
Upvotes: 1