电商网站订单评价得分的星级样式实现

news/2024/5/8 23:42:56/文章来源:https://blog.csdn.net/weixin_30375247/article/details/97669229

概述:

电商网站中的订单一般都允许评价,比如质量评价和服务评价等,页面上以星星多少表示评价的高低。

(以下截图来源于京东)

本文基于自己的理解和实现“五星级评价”,供参考。

----------------------------------------------------------------------------

前期准备:

    从京东订单页面中拷贝了一个图片,此处命名为star-s.png。

图片star-s.png:

    

图片分析:

    像素160×15px,包含5个满星和5个空星,每个星星的像素都是15×15px,左对齐,最右边留有15×15px的空白(暂时没理解这片空白区域的用途)。

----------------------------------------------------------------------------

第一部分:静态得分呈现

功能:

    已评价的订单显示出具体的星级得分。

实现方式:

    评价区域的div尺寸为75×15px,将背景图片设置为star-s.png,div区域正好显示五颗星。

    星级的不同完全取决于图片的background-position-x值,以15px为单位,初始值设置为-75px时,页面显示出来的是空星,即得分是零颗星。如果得分设置为一颗星,则将图片右移15px,即background-position-x的值增加15px至-60px。其他星级得分以此类推。

具体代码:

       将不同的星级参数background-position-x值以类名区分,不同的星级得分设置为具体的类名即可。

(样式代码)

 1            /*星级图片区域div的样式*/
 2            .star-s
 3             {
 4                 display:inline-block;
 5                 height:15px;
 6                 width:75px;
 7                 background-image:url("star-s.png");
 8             }
 9             /*零颗星的样式*/
10             .s0
11             {
12                 background-position-x:-75px;
13             }
14             /*一颗星的样式*/
15             .s1
16             {
17                 background-position-x:-60px;
18             }
19             /*两颗星的样式*/
20             .s2
21             {
22                 background-position-x:-45px;
23             }
24             /*三颗星的样式*/
25             .s3
26             {
27                 background-position-x:-30px;
28             }
29             /*四颗星的样式*/
30             .s4
31             {
32                 background-position-x:-15px;
33             }
34             /*五颗星的样式*/
35             .s5
36             {
37                 background-position-x:0px;
38             }
View Code

(HTML代码)

1             零颗星<div class="star-s s0"></div><br/>
2             一颗星<div class="star-s s1"></div><br/>
3             两颗星<div class="star-s s2"></div><br/>
4             三颗星<div class="star-s s3"></div><br/>
5             四颗星<div class="star-s s4"></div><br/>
6             五颗星<div class="star-s s5"></div>
View Code

(呈现效果)

第二部分:动态实现评价得分

功能

    未评价的订单允许用户通过鼠标点击星级图片给订单打分。

实现方式:

    由于星级图片的呈现区域大小固定,鼠标进入该区域后需要获取到鼠标相对于该区域左侧的距离,根据该距离与15px的关系,动态调整该div的类名以实现星级图片的改变。

    监控每个星级区域div的mousemove事件,获取该事件的参数e,e.offsetX表示鼠标距离该div左侧的距离。根据e.offsetX/15得到的整数来确定当前鼠标所处的星级。

具体代码:

    封装一个公用函数,传入星级图片所在div的id,返回鼠标点击星级图片后的分数值(默认得分为1分,可自设)。

(HTML代码)

1             质量评价<div id="quality" class="star-s"></div><br/>
2             服务评价<div id="service" class="star-s"></div>
View Code

(JavaScript代码)

 1                /*封装函数*/
 2                function StarComment(eleID) {
 3                 var starValue = 1;
 4                 var tar = $("#" + eleID)[0];
 5                 var dealMousemove=function(e) {
 6                     var that = e;
 7                     console.log(e.offsetX);
 8                     starValue = parseInt(e.offsetX / 15) + 1;
 9                     tar.className = "star-s s" + starValue.toString();
10                     console.log(tar.className);
11                 }
12                 $(tar).bind("mousemove", function (e) {
13                     dealMousemove(e);
14                 });
15                 $(tar).bind("click", function () {
16                     $(tar).unbind("mousemove")
17                 });
18                 
19                 /*开放接口函数:返回div的星级分数*/
20                 this.getStarValue=function(){
21                     return starValue;
22                 }
23             }
24 
25             /*根据需要初始化指定的div,给其赋予星级得分功能*/
26             var starQuality = new StarComment("quality");
27             var starService = new StarComment("service");
View Code

(呈现效果)

 

完整代码附后:

 1 <html>
 2     <head>
 3         <script src="jquery-1.9.1.js"></script>
 4         <script src="jquery-1.9.1.min.js"></script>
 5         <style type="text/css">
 6             .star-s
 7             {
 8                 display:inline-block;
 9                 height:15px;
10                 width:75px;
11                 background-image:url("star-s.png");
12             }
13             .s0
14             {
15                 background-position-x:-75px;
16             }
17             .s1
18             {
19                 background-position-x:-60px;
20             }
21             .s2
22             {
23                 background-position-x:-45px;
24             }
25             .s3
26             {
27                 background-position-x:-30px;
28             }
29             .s4
30             {
31                 background-position-x:-15px;
32             }
33             .s5
34             {
35                 background-position-x:0px;
36             }
37 
38         </style>
39     </head>
40     <body>
41         <div >
42             零颗星<div class="star-s s0"></div><br/>
43             一颗星<div class="star-s s1"></div><br/>
44             两颗星<div class="star-s s2"></div><br/>
45             三颗星<div class="star-s s3"></div><br/>
46             四颗星<div class="star-s s4"></div><br/>
47             五颗星<div class="star-s s5"></div>
48         </div>
49         <div >
50             质量评价<div id="quality" class="star-s"></div><br/>
51             服务评价<div id="service" class="star-s"></div>
52         </div>
53 
54         <script type="text/javascript">
55             
56             function StarComment(eleID) {
57                 var starValue = 1;
58                 var tar = $("#" + eleID)[0];
59                 var dealMousemove=function(e) {
60                     var that = e;
61                     console.log(e.offsetX);
62                     starValue = parseInt(e.offsetX / 15) + 1;
63                     tar.className = "star-s s" + starValue.toString();
64                     console.log(tar.className);
65                 }
66                 $(tar).bind("mousemove", function (e) {
67                     dealMousemove(e);
68                 });
69                 $(tar).bind("click", function () {
70                     $(tar).unbind("mousemove")
71                 });
72                 
73                 this.getStarValue=function(){
74                     return starValue;
75                 }
76             }
77 
78             var starQuality = new StarComment("quality");
79             var starService = new StarComment("service");
80         </script>
81     </body>
82 </html>
View Code

 

转载于:https://www.cnblogs.com/mzyj/p/5350007.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_816232.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

几个不错的java类、jar包及其依赖查找网站

转自&#xff1a;http://my.oschina.net/leeoo/blog/51062 http://www.findjar.com/index.x http://www.jarvana.com/jarvana/ &#xff08;强烈推荐&#xff0c;界面不错&#xff0c;而且信息非常详细&#xff0c;是目前发现的最好的&#xff01;&#xff01;&#xff01;可是…

新站4个月,新手做网站经验总结

我&#xff0c;一个小小的90后草根站长&#xff0c;14年年底接触建站&#xff0c;到现在刚刚半年多。半年来&#xff0c;做了三个网站&#xff0c;前两个由于种种原因相继夭折&#xff0c;不再多提&#xff0c;现在一直在运营的网站&#xff0c;域名是创建于2015年3月2日&#…

爬虫概念与编程学习之如何爬取视频网站页面(三)

先看&#xff0c;前一期博客&#xff0c;理清好思路。 爬虫概念与编程学习之如何爬取网页源代码&#xff08;一&#xff09; 爬虫概念与编程学习之如何爬取视频网站页面&#xff08;用HttpClient&#xff09;&#xff08;二&#xff09; 不多说&#xff0c;直接上代码。 编写代…

调用腾讯qq接口实现网站客服qq

通过调用腾讯接口,可以实现qq客服功能 <a href"tencent://message/?uin$!{item.qqNum}&Sitewww.qianfu360.com&Menuyes" target"_blank"><img src"http://wpa.qq.com/pa?p1:$!{item.qqNum}:6" height"8" border &q…

MiniARM工控核心板之浅谈TF卡电路设计(转载于周立功网站)

转载于&#xff1a; http://www.zlg.cn/ipc/article/detail/id/525.html Micro SD卡&#xff08;又称TF卡&#xff09;是一种极细小的快闪存储器卡&#xff0c;原本这种记忆卡称为T-Flash&#xff0c;后来改为TransFlash&#xff08;TF卡&#xff09;&#xff1b;而重新命名为M…

分享30个漂亮的免费 PSD 网站模板

非常感谢那些很有才华的设计师分享它们的劳动成果&#xff0c;让更多的人可以使用他们的创意设计。今天&#xff0c;本文与大家分享30个漂亮的免费 PSD 网站模板&#xff0c;点击图片下面的下载链接即可免费下载&#xff0c;看看有没您喜欢的。 1.) Shape 2.) Fantastic Soccer…

windows添加引导菜单_如何将网站链接添加到Windows 10开始菜单

windows添加引导菜单Windows 10’s Start menu is very customizable. Add website shortcuts to your Start menu and you can quickly access your favorite websites by clicking a tile. This works with Microsoft Edge, Google Chrome, or any other browser. Windows 10…

页面缓存url缓存对象缓存_使用此URL技巧快速加载任何网站的缓存版本

页面缓存url缓存对象缓存Can’t get a particular page to open? Just add cache: in front of the URL and Google’s cached copy will open instantly. 无法打开特定页面&#xff1f; 只需添加cache:在URL之前&#xff0c;Google的缓存副本将立即打开。 Nick Douglas, wri…

ipad和iphone适配_如何查看和删除网站在iPhone或iPad上保存的所有数据

ipad和iphone适配Whenever you visit a website on an iPhone or iPad, snippets of data are saved to your device. Cookies and other cached data eventually start to take up significant space, so you may want to clean them out. Here’s how. 每当您在iPhone或iPad上…

ipad上能否适用zoom_Zoom使网站即使在Windows上也无需征得您的同意就开始拍摄您...

ipad上能否适用zoomZoom’s video conferencing software has more problems than a secret web server on Mac. Even on Windows, websites you visit could start filming you without your consent. All you have to do is click a link. This problem affects Macs, too. Z…

opera 导出书签_使用昵称在Opera中快速打开一组带有书签的网站

opera 导出书签If you have a specific set of websites you visit often, you can make it easy to open all those websites at once using a bookmarks folder and a nickname. Typing a folder’s nickname in the address bar opens all the websites in that folder. 如果…

windows删除桌面ie_在Windows 8的桌面IE中打开固定的Metro网站图块

windows删除桌面ieThe ability to pin websites to your Start Screen is a nice touch in Windows 8, however by default the sites you pin open with the Metro version of Internet Explorer. Here’s how to change that. 在Windows 8中&#xff0c;将网站固定到“开始”…

SEM和SEO的区别?

https://www.zhihu.com/question/20307058 SEM在营销中扮演的角色&#xff1a;进攻 搜索引擎营销&#xff0c;即SEM(Search Engine Marketing)&#xff0c;是基于搜索引擎平台的营销活动&#xff0c;泛指在搜索引擎平台的广告推广和管理。 SEM的优势&#xff1a;门槛低、见效快…

移动 禁用github_如何在手机上禁用网站的移动版本

移动 禁用githubMany websites, including How-to Geek, display a mobile version for users that are browsing the site on their phone. This is done to reduce bandwidth and look better on a smaller screen and resolution, but sometimes you really just want the …

大型分布式网站架构设计与实践

大型分布式网站架构设计与实践&#xff08;一线工作经验总结&#xff0c;囊括大型分布式网站所需技术的全貌、架构设计的核心原理与典型案例、常见问题及解决方案&#xff0c;有细节、接地气/京东&#xff1a;大型分布式网站所需技术的全貌、架构设计的核心原理与典型案例、常见…

火狐 脆弱的加密_将自动网站加密添加到Firefox

火狐 脆弱的加密Would you like to have websites automatically open encrypted and secure? Enable a set list of websites and the ability to create encryption rule sets of your own with the HTTPS Everywhere extension for Firefox. 您想让网站自动打开加密且安全的…

chrome查找快捷键_使用Chrome标志查找网站的实际位置

chrome查找快捷键Have you been wanting Firefox’s “Flagfox Extension” goodness in Google Chrome? Now you can get it with the Chrome Flags extension. 您是否一直想在Google Chrome浏览器中使用Firefox的“ Flagfox Extension”功能&#xff1f; 现在&#xff0c;您…

在Windows 7中使用搜索连接器从您的桌面搜索网站

The new Windows 7 Search is greatly improved over previous versions and allows you to search for data on local and networked machines. Today we take it a step further and show you how to extend the search capability to sites on the Internet. 与以前的版本相…

IIS发布网站出错解决方案

1、第一类错误&#xff08;Web服务器被配置为不列出此目录的内容&#xff09; 问题所在没有为请求的URL设置默认文档&#xff0c;在IIS“默认文档”添加一个你要访问的默认文档名字&#xff0c;如&#xff1a;Default.aspx。 2、第二类错误&#xff08;请求的内容似乎是脚本&am…

常用SEO优化

转载于:https://www.cnblogs.com/alonesky/p/10619003.html