欢迎您访问南京安优网络官方网站,本公司专注于:网站制作、小程序开发、网站推广。 24小时服务热线:400-8793-956
当前位置:南京网站制作公司 > 资讯中心 > 网站知识
南京小程序开发公司教你实现微信小程序星级评价效果
来源:南京网站制作 时间:2019-05-20 08:49:10

南京小程序开发公司将在本文中,给出了一个例子来分享微信applet的具体代码来实现日历效果。供您参考,详情如下。

 
效果预览:

wxml代码部分:
 
<view class='topMaxBox'>
 <view class='topLeft' style='width: {{ imgW }}px; height: {{ imgW }}px; flex: {{ imgW }}px 0 0;'>
 <image src='http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg'></image>
 </view>
 <view class='topRight'>
 <view class='r_top'>
  < text > commodity name </text >
  <text>{{ evaluate }}</text>
 </view>
 <view class='r_bottom' catchtouchmove='moveFun' catchtouchstart='moveFun'>
  <image src='{{ starSrc }}'></image>
 </view>
 </view>
</view>
wxss代码部分:
 
 
.topMaxBox{
 padding: 5%;
 display: flex;
 flex-direction: row;
}
 
.topLeft{
 border: 1px solid #e5e5e5;
 margin-right: 10px;
}
 
.topLeft image{
 width: 100%;
 height: 100%;
}
 
.topRight{
 flex: 1;
 display: flex;
 flex-direction: column;
 justify-content: center;
}
 
.r_top{
 display: flex;
 justify-content: space-between;
 margin-bottom: 2%;
}
 
.r_bottom image{
 width: 130px;
 height: 18px;
}
 
应用。sysInfo()封装在app中。JS文件供全球使用。这是代码部分
 
/**
 * Getting System Information
 */
 sysInfo: function () {
 let res = wx.getSystemInfoSync();
 let info = {
  Width: res. Windows Width, // Available Window Width
  Height: res. windows Height, // usable window height
  System: res. system, // OS version
  StatusBarHeight: res.statusBarHeight// Height of the status bar
 }
 return info;
 },
JS代码部分:
 
const app = new getApp();
 
// page/issueEvaluate/issueEvaluate.js
Page({
 
 /**
 * Initial data of pages
 */
 data: {
 ImgW: app. sysInfo (). width * 0.146, /// Set the image width dynamically according to the screen width
 StarLen: 5, // Star Evaluation Initial Level
 StarSrcArr: ['. /.. / image / star2-1. png','. /. / image / star2-2. png','.. /. / image / star2-3. png','. /. / image / star2-4. png','. /. / image / star2-4. png','. /. / image / star2-5. png','. /.. / image / star2-6. png', //star evaluation image resource array
 StarSrc:'. /. / image / star2-6. png', // initial picture of star evaluation
 Evaluate:'Very good',
 EvaluateArr: ['Very bad','poor','average','good','better','Very good']
 },
 
 moveFun: function (e) {
 Let imgBoxW = app. sysInfo (). width * 0.146 + 10; // end coordinates of X axis of commodity picture (i.e. initial coordinate values of stars)
 Let starW = 130/5; // The width of each star (used to calculate the X-axis coordinates of stars)
 Let xAxial = e.touches [0]. clientX; // Get the X-axis coordinates of the current touch
 
 // If the X-axis coordinate of the current touch is less than the initial coordinate, it will be displayed as 0 stars.
 if (xAxial < imgBoxW) {
  this.data.starLen = 0;
  // If the X-axis coordinate of the current touch is larger than the initial coordinate and smaller than the initial coordinate of the second star, it is shown as a star.
 } else if (imgBoxW + (starW * 2) > xAxial && xAxial > imgBoxW) {
  this.data.starLen = 1;
  // If the X-axis coordinate of the current touch is greater than the initial coordinate of the second star and less than the initial coordinate of the third star, it is shown as two stars.
 } else if (imgBoxW + (starW * 3) > xAxial && xAxial > imgBoxW + (starW * 2)) {
  this.data.starLen = 2;
  // If the X-axis coordinate of the current touch is greater than the initial coordinate of the third star and less than the initial coordinate of the fourth star, it is shown as three stars.
 } else if (imgBoxW + (starW * 4) > xAxial && xAxial > imgBoxW + (starW * 3)) {
  this.data.starLen = 3;
  // If the X-axis coordinate of the current touch is greater than the initial coordinate of the fourth star and less than the initial coordinate of the fifth star, it is shown as four stars.
 } else if (imgBoxW + (starW * 5) > xAxial && xAxial > imgBoxW + (starW * 4)) {
  this.data.starLen = 4;
  // If the X-axis coordinate of the current touch is greater than the initial coordinate of the fifth star, it will be displayed as five stars.
 } else if (xAxial > imgBoxW + (starW * 5)) {
  this.data.starLen = 5;
 }
 // Substitute the SRC path with the IMG tag to the corresponding star image
 this.data.starSrc = this.data.starSrcArr[this.data.starLen];
 // Set to the corresponding evaluation level text
 this.data.evaluate = this.data.evaluateArr[this.data.starLen];
 this.setData({
  starSrc: this.data.starSrc,
  evaluate: this.data.evaluate
 });
 },
 
})
以上是本文的全部内容。我希望它对每个人的学习都有所帮助,我希望你能更多地支持南京小程序开发公司我们。

本文地址:http://www.njanyou.cn/web/2500.html
Tag:
专业服务:南京网站制作,南京网站制作公司,南京网站建设公司
联系电话:025-65016872
上一篇: 南京小程序开发说说微信小程序中时间控制选择器视图的详细用法
下一篇: 使用面包屑导航改善用户体验的方法
最新案例
永银
永银
珠海跨境电商
珠海跨境电商
五颗星商城
五颗星商城
上海万客生鲜超市
上海万客生鲜超市
一九在线商城
一九在线商城
你可能感兴趣
使用选择轮使网站导航变得有趣的便捷指南
在您的网站上使用不寻常和醒目的颜色的 6 种方法
花店的基本数字营销策略
SEO的内部链接最佳实践
捕捉自信:摄影在男士时尚品牌中的作用
2024年房地产网站的创新网页设计趋势
南京网站制作说说哪些关键因素使商业网站成功?
南京网站制作公司分享使用 iPhone 拍摄更好网站照片的 7 个技巧
最后更新
南京网页制作开发在 SEO 中的作用 南京网站设计的几个技巧帮助你的论文更有趣和吸引人 南京网站建设是如何在 Photoshop 中创建网站横幅 南京网站制作公司如何为您的企业选择最佳的电子邮件营销软件 南京网站制作:您需要聘请网站设计公司的 10 个理由 南京网站设计:2024 个流行的网站设计趋势 如果需要改造在线商店南京网站建设认为需要考虑的 8 件事 南京网站制作公司分享使用 iPhone 拍摄更好网站照片的 7 个技巧
服务项目
南京网站制作 营销型网站 微信营销 IDC网站 精品案例