angularjs实现星星评分
angularjs实现星星评分
自定义指令
app.directive('myStars', function () {
return {
require : '?ngModel', // ?ngModel
restrict : 'E',
replace : true,
templateUrl : 'ui/templateUrl/myStars.html',
scope: {ngModel : '='},
link: function ($scope, element, attrs, ngModel) {
$scope.myStars = [1,2,3,4,5];
$scope.clickCnt = 1;
$scope.$watch('ngModel', function(newValue) {
var dataList = newValue;
console.log(dataList);
if(!dataList) return;
$scope.myStar = dataList;
$scope.clickCnt = dataList;
})
$scope.stars = function (myStar) {
$scope.clickCnt = myStar;
ngModel.$setViewValue(myStar);
}
$scope.mouseoverStar = function (myStar) {
$scope.hoverCnt = myStar;
}
$scope.mouseleaveStar = function (myStar) {
$scope.hoverCnt = 1;
}
}
}
});
里面的myStars.html
<div>
<meta charset="utf-8">
<ul class="my-stars-list">
<li class="my-stars-items" ng-mouseover="mouseoverStar(myStar)" ng-mouseleave="mouseleaveStar(maStar)" ng-click="stars(myStar)" ng-class="{myStarsSel: clickCnt > $index , myStarHover: hoverCnt > $index }" ng-repeat="myStar in myStars track by $index" title="{{ myStar }}星">{{ myStar }}</li>
</ul>
</div>
html中的使用如下:
<my-stars ng-model="drLevel"></my-stars>
css样式:
.my-stars-list{
height: 34px;
line-height: 34px;
display: -webkit-box;
display: -webkit-flex;
display: flex;
}
.my-stars-items{
cursor:pointer;
font-size:;
width: 34px;
line-height: 34px;
height:34px;
background-image: url(../images/star-off-big.png);
background-repeat: no-repeat;
background-position: center center;
}
.myStarHover.my-stars-items{
background-image: url(../images/star-on-big.png);
background-repeat: no-repeat;
background-position: center center;
}
.myStarsSel.my-stars-items{
background-image: url(../images/star-on-big.png);
background-repeat: no-repeat;
background-position: center center;
}
css中的图片:


完成的效果:

获取点击的是多少直接
var level = $scope.drLevel;
angularjs实现星星评分的更多相关文章
- HTML5商城开发三 jquery 星星评分插件
展示:
- js点亮星星评分并获取参数的js代码
点亮星星评分后,点击按钮,立即获得分数参数值,方便不想使用ajax传参的朋友 http://demo.jb51.net/js/2014/jsxxdf/demo2.html <!DOCTYPE h ...
- vue2.0:(九)、外卖App弹窗部分星星评分
本篇是星星评分部分,先上代码: 1.header.vue: <template> <transition name="fade"> & ...
- angularJs实现星星等级评分
星期六加班,教育后台也要有星级评分等级的需求,醉了……基本知道些怎么做,网上也随便找了找,没什么合意的,毕竟需求不同,也不能完全一样不是.学习之,改之╮(╯▽╰)╭ Directive angular ...
- Android星星评分控件RatingBar的使用
在Android的开发中,有一个叫做评分控件RatingBar,我们可以使用该控件做等级划分.评分等作用,星星形状显示,也可以半星级别,我们来看一下评分控件如何使用. 布局文件中定义控件以及属性,这里 ...
- 微信小程序——星星评分
先来个效果图镇楼: 实现原理: 1.循环需要评分的列表,判断它的分数 与 当前星星索引的大小: 2.点击,获取星星对应的分数,让星星高亮. 代码: star.wxml: <view class= ...
- ivew使用星星评分
这组件好像有问题,不知道是我们项目环境造成的还是什么,初始化半星不能正常显示,显示的全星. 1.template <div style="display:inline-block;ma ...
- vue 星星评分组件
显示评分和打分组件,可现实半颗星星效果 效果图: 参数名 类型 说明 score Number 分数 ,默认0,保留一位小数 disabled Boolean 是否只读,默认false,鼠标点击可以打 ...
- wex5中的星星评分
新建一个空白的.w文件,然后在页面上放5个img星星图片 重要的是图片路径不能是绝对路径,要用相对路径,不然js操作的时候会出bug 添加两个label标签(标签随你挑,在这我就用label) 你到时 ...
随机推荐
- Avalondock 第四步 边缘停靠
前一章介绍了分组功能,这一章主要介绍细节信息,LayoutRoot的side属性 LayoutRoot包含四个属性,LeftSide,RightSide,TopSide,BottomSide,分别用于 ...
- Powershell Get File/Disk Size
知识点: 1.获取路径中的文件夹:Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $True} | Sort-Obje ...
- mvel
https://en.wikipedia.org/wiki/MVEL import java.util.*; // the main quicksort algorithm def quicksort ...
- oracle在drop表时要注意
在oracle中,比如 drop table STC_GHSLB; 系统同时自动删除的有这个表的主键.索引.trigger. 不能同时自动删除的有:sequence. 因为sequence不跟表关联, ...
- 【MonogDB】The description of index(二) Embedded and document Index
In this blog, we will talk about another the index which was called "The embedded ". First ...
- struts2的HelloWorld的基本过程
login.jsp中 <form action="Login"... 该页面提交后, web.xml中设置的过滤器会起作用 <filter> ...
- io.Writer
var w io.Writer // 设置为你的 io.Writer var b bytes.Buffer fmt.Fprint(&b, "Hello World") w ...
- error:No resource found that matches the given name 'Theme.AppCompat.Light'
一.stsckoverflow http://stackoverflow.com/questions/17870881/cant-find-theme-appcompat-light-for-new- ...
- Webbench进行网站压力测试
今天突然发现一个新大陆,Webbench,是linux下,用这很方便,开源,不限制并发访问次数和时间....大爱啊! 下载Webbench 使用wget 或者windows下载好导入linux也行, ...
- Web Service简单demo
最近开发因需求要求需要提供Web Service接口供外部调用,由于之前没有研究过该技术,故查阅资料研究了一番,所以写下来记录一下,方便后续使用. 这个demo采用CXF框架进行开发,后续所提到的We ...