微信小程序实现星星评价效果
作者:Stevin的技术博客 发布时间:2023-08-24 10:04:45
标签:微信小程序,星星评价
本文实例为大家分享了微信小程序实现星星评价效果的具体代码,供大家参考,具体内容如下
代码实现
wxml文件
<!--pages/evaluatepage/evaluatepage.wxml-->
<view class='container'>
<view class='evaluate_contant'>
<!--外层循环控制有几个评价条目 -->
<block wx:for='{{evaluate_contant}}' wx:key='' wx:for-index='idx'>
<view class='evaluate_item'>
<view class='evaluate_title'>{{item}}</view>
<!--星星评价 -->
<view class='evaluate_box'>
<!--内层循环展示每个评价条目的星星 -->
<block wx:for="{{stars}}" wx:key=''>
<image class="star-image" style="left: {{item*80}}rpx" src="{{scores[idx] > item ?(scores[idx]-item == 0.5?halfSrc:selectedSrc) : normalSrc}}">
<view class="item" style="left:0rpx" data-score="{{item + 0.5}}" data-idx='{{idx}}' bindtap="selectLeft"></view>
<view class="item" style="left:20rpx" data-score="{{item + 1}}" data-idx='{{idx}}' bindtap="selectRight"></view>
</image>
</block>
</view>
</view>
</block>
<button class='submit_button' bindtap='submit_evaluate' type='primary'>提交</button>
</view>
</view>
js文件
Page({
data: {
evaluate_contant: ['评价条目一', '评价条目二', '评价条目三',],
stars: [0, 1, 2, 3, 4],
normalSrc: '../../images/no-star.png',
selectedSrc: '../../images/full-star.png',
halfSrc: '../../images/half-star.png',
score: 0,
scores: [0, 0, 0],
},
// 提交事件
submit_evaluate: function () {
console.log('评价得分' + this.data.scores)
},
//点击左边,半颗星
selectLeft: function (e) {
var score = e.currentTarget.dataset.score
if (this.data.score == 0.5 && e.currentTarget.dataset.score == 0.5) {
score = 0;
}
this.data.scores[e.currentTarget.dataset.idx] = score,
this.setData({
scores: this.data.scores,
score: score
})
},
//点击右边,整颗星
selectRight: function (e) {
var score = e.currentTarget.dataset.score
this.data.scores[e.currentTarget.dataset.idx] = score,
this.setData({
scores: this.data.scores,
score: score
})
}
})
wxss
/*评价区域 */
.container .evaluate_contant .evaluate_item {
font-size: 30rpx;
color: gray;
margin-left: 20rpx;
margin-top: 30rpx;
}
/*评价标题 */
.container .evaluate_contant .evaluate_item .evaluate_title {
display: inline-block;
}
/*评价盒子 */
.container .evaluate_contant .evaluate_item .evaluate_box {
position: absolute;
left: 220rpx;
width: 100%;
display: inline-block;
}
/*星星评价的每个图片 */
.container .evaluate_contant .evaluate_item .evaluate_box .star-image {
position: absolute;
width: 40rpx;
height: 40rpx;
src: "../../images/no-star.png";
}
/*星星的左边和右边区域<点击左边半个星星,点击右边整个星星> */
.container .evaluate_contant .evaluate_item .evaluate_box .star-image .item {
position: absolute;
top: 0rpx;
width: 20rpx;
height: 40rpx;
}
/*按钮 */
.container .evaluate_contant .submit_button {
height: 60rpx;
font-size: 30rpx;
line-height: 60rpx;
margin: 20rpx;
}
来源:https://blog.csdn.net/feng2qing/article/details/79366249


猜你喜欢
- 由于不同的浏览器,比如Internet Explorer 6,Internet Explorer 7,Mozilla Firefox等,对C
- PHP getName() 函数实例返回 XML 元素及其子元素的名称:<?php $xml=<<<XML<?
- 网页的布局也许是大家最不放在眼里的地方,其实布局地位如同文字的排版一样,随便可布,布即随便。但是看过我上篇《网页设计技巧系列 之 文本排版》
- 远程连接oracle只用PLSQLDeveloper客户端,不配置tnsnames.ora文件在PL/SQL中填写:1.UserName:用
- 采集开始第一步是分析要采集的页面。使用浏览器打开要采集的页面(如:http://sports.sina.com.cn/k/2008-09-1
- 一、http协议无状态问题http协议没有提供多次请求之间的关联功能,协议的本意也并未考虑到多次请求之间的状态维持,每一次请求都被协议认为是
- 将来电脑的大显示屏会越来越普及,并且从现在web设计作品中能观察到两点趋势:页面布局普遍更宽;页面内容文字普遍更大。使用1280×800和1
- 今天也碰到了el表达式无法解析的事情,于是在网上查询了下,大多说是因为web.xml中声明的版本问题于是收集了如下版本:web-app_2_
- 最近,W3C的一项公告称,在W3C与XHTML2的合同于今年年底到期后将不会续签。这意味着W3C停止了对XHTML2的开发,转而大力支持HT
- 最近有网友在留言板里问到jRaiser和jQuery的冲突问题,特此写一篇文章进行解释。冲突的根源众所周知,jQuery是通过一个全局变量$
- 例:公司员工采取三个轮班制度:凌晨0:00到早上8:00为第一班,早上8:00到下午4:00为第二班,下午4:00到晚上12:00为第三班。
- 先看下面例子的效果:<INPUT TYPE="text" NAME=""&
- 问题:如果一个网站拥有两个域名:domain1.com和domain2.com。在网站运营前期,主推domain1.com,但发展到中期,由
- 在Dreamweaver4中,你可以存储你自己设定的图片、链接、flash影片、颜色表、模板等等,组成这个站点的资产,这就是Assets面板
- 高层的期望“3个月内,我希望网站能增加X注册用户,每日的独立IP到Y,网站盈利达到Z……”作为一个团队的领袖或者产品负责人,这样的期望是根据
- 如何在网上查找链接? 见下:findlinks.html<html><head>
- 这段时间在处理SQL server 2000 SP4补丁打不上的问题上花了不少时间,回头想想应该总结一下:系统说明:dell1800服务器,
- 定义:Dim MyArray() Redim MyArray(5)Session("StoredAr
- (一)深入浅出理解索引结构实际上,您可以把索引理解为一种特殊的目录。微软的SQL SERVER提供了两种索引:聚集索引(clustered
- 一共4个页面:form.asp; chk.asp; num.asp; count.asp得到一个随即数字。加密