作者:形同陌路2502906543 | 来源:互联网 | 2023-05-16 02:56
.wxml
<block wx:for="{{stars}}">
<image class="star-image" src="{{key > item ?(key-item == 0.5?halfSrc:selectedSrc) : normalSrc}}">
<view class="tag">
<view class="item" data-key="{{item+0.5}}" bindtap="selectLeft">view>
<view class="item" data-key="{{item+1}}" bindtap="selectRight">view>
view>
image>
block>
.wcss
.star-image {
width: 16px;
height: 16px;
margin-left: 30px;
margin-top: 30px;
}
.item {
float: left;
width: 8px;
height: 16px;
}
.tag {
display:inline-block;
position: absolute;
top: 30px;
}
.js
var app = getApp()
Page({
data: {
stars: [0, 1, 2, 3, 4],
normalSrc: '../../image/imgs/star.png',
selectedSrc: '../../image/imgs/status.png',
halfSrc: '../../image/icons/coin.png',
key: 0,
},
onLoad: function () {
},
selectLeft: function (e) {
var key = e.currentTarget.dataset.key
if (this.data.key == 0.5 && e.currentTarget.dataset.key == 0.5) {
key = 0;
}
console.log("得" + key + "分")
this.setData({
key: key
})
},
selectRight: function (e) {
var key = e.currentTarget.dataset.key
console.log("得" + key + "分")
this.setData({
key: key
})
}
})