jquery+css实现简单的评分功能
2013-01-29 15:56
519 查看
今天研究了下简单的评分功能,参考了下"http://www.lanxyou.info/star-rating-new-method/",感觉比较简单易用,之后自己做了下优化处理。
先看下效果图:
原理:橙色星宽度/父容器宽度 * 100 = 分值
功能:鼠标悬浮时,其左侧星星点亮
鼠标滑过时,其左侧星星点亮
鼠标点击时,其左侧星星点亮
鼠标移开后,默认记忆上次点击的橙色星宽度
所需图片:
实现源码:
先看下效果图:
原理:橙色星宽度/父容器宽度 * 100 = 分值
功能:鼠标悬浮时,其左侧星星点亮
鼠标滑过时,其左侧星星点亮
鼠标点击时,其左侧星星点亮
鼠标移开后,默认记忆上次点击的橙色星宽度
所需图片:
实现源码:
<!doctype html> <html> <head> <meta charset="utf-8"> <script src="jquery.js" type="text/javascript"></script> <title>jquery+css实现简单评分功能</title> <style> .rating{ float:left; height:23px; width:115px; background:url('star.png') repeat-x 0 0; cursor:pointer; } .rating a{ display:block; height:100%; width:0; background:url('star.png') repeat-x 0 -23px; } #score{ float:left; margin-left:10px; font-family:'微软雅黑'; font-size:18px; } #score em{ color:#FF6600; font-weight:bold; padding:10px; } </style> </head> <body> <div id="rating" class="rating" ><a></a></div> <div id="score"><em>0</em>分</div> <script> var rating=$('#rating'); var leftRating = rating.offset().left, width = rating.width(), clickWidth = 0; rating.mouseover(function(e){ var overWidth=parseInt(((e.pageX-leftRating)/width)*100,10); $(this).find('a').css({'width':(overWidth+'%')}); }); rating.mouseout(function(){ $(this).find('a').css({'width':(clickWidth)+'%'}); }); rating.mousemove(function(e){ var hoverWidth=parseInt(((e.pageX-leftRating)/width)*100,10); $(this).find('a').css({'width':(hoverWidth+'%')}); }); rating.click(function(e){ clickWidth=parseInt(((e.pageX-leftRating)/width)*100,10); $(this).find('a').css({'width':(clickWidth+'%')}); $('#score em').text(clickWidth); }); </script> </body> </html>
相关文章推荐
- jquery+css实现简单的评分功能
- 用css和jQuery实现简单的购物车功能
- div+css+jQuery简单实现投票功能
- html+css+jQuery实现多种图片简单切换功能大综合
- html+css+jQuery实现多种图片简单切换功能大综合
- 用css和jQuery实现简单的购物车功能
- div+css+jQuery简单实现投票功能..
- js+html+css实现简单页面交互功能(2015知乎前端笔试题)http://v.youku.com/v_show/id_XMTI0ODQ5NTAyOA==.html?from=y1.7-1.2
- Jquery 和CSS 实现的tabs选项卡功能
- jquery+css实现简单二级下拉菜单导航
- CSS+ jquery实现表格嵌套功能
- jquery实现简单的tabs插件功能
- jquery中实现简单的tabs插件功能的代码
- html+css+jQuery+JavaScript实现tab自动切换功能
- 纯CSS实现箭头、气泡让提示功能具有三角形图标(简单实例)
- jquery 实现的一款超简单的图片切换功能
- thinkphp使用ajax、jquery、Mysql实现了简单的客户端通信功能
- jQuery实现一个简单的验证码功能
- jQuery实现简单日期格式化功能示例