-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethod1.html
More file actions
78 lines (71 loc) · 2.08 KB
/
method1.html
File metadata and controls
78 lines (71 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rating</title>
<style media="screen">
body, ul, li {
margin: 0;
padding: 0;
}
li {
list-style: none;
display: inline-block;
}
.rating {
width: 550px;
height: 100px;
margin: 100px auto;
}
.rating-item {
width: 100px;
height: 100px;
background: url(img/star.png) no-repeat;
cursor: pointer;
}
.active {
background: url(img/full-star.png) no-repeat;
}
</style>
</head>
<body>
<ul class="rating" id="rating">
<li class="rating-item" title="Very Bad"></li>
<li class="rating-item" title="Bad"></li>
<li class="rating-item" title="Fair"></li>
<li class="rating-item" title="Good"></li>
<li class="rating-item" title="Awesome"></li>
</ul>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
(function(){
//init light stars number
var num = 0,
$rating = $('#rating');
$star = $rating.find('.rating-item');
//light on
var lightOn = function(num) {
$star.each(function(i){
if(i < num) {
$(this).addClass('active');
}else{
$(this).removeClass('active');
}
});
};
//init
lightOn(num);
//user event
$star.on('mouseover', function(){
lightOn($(this).index() + 1);
});
$star.on('click', function(){
num = $(this).index() + 1;
});
$rating.on('mouseout', function(){
lightOn(num);
});
})();
</script>
</body>
</html>