Home > WeChat Applet > Mini Program Development > Five-star reviews in WeChat mini program

Five-star reviews in WeChat mini program

高洛峰
Release: 2017-02-27 14:29:04
Original
3786 people have browsed it

We often have reviews for services or items. The common way is five stars, which can be quickly achieved by touching.


Let’s take a look at the renderings first:

Five-star reviews in WeChat mini program

As shown in the picture above, here we want to add three five-star reviews. The first [description matches], the second [delivery speed], and the third [service attitude].

Let’s explain here the comment of “matching the description”
WXML code

<!--星星评价-->
  <view class="comment1-description" style="display:flex;flex-direction:row;">
  <view class="comment1-description1">描述相符</view>
  <view  class="star-pos" style="display:flex;flex-direction:row;">
       <view class="stars  {{flag0>=1? &#39;on&#39;: &#39;&#39;}}"  bindtap="changeColor1"></view>
       <view class="stars  {{flag0>=2? &#39;on&#39;: &#39;&#39;}}"  bindtap="changeColor2"></view>
       <view class="stars  {{flag0>=3? &#39;on&#39;: &#39;&#39;}}"  bindtap="changeColor3"></view>
       <view class="stars  {{flag0>=4? &#39;on&#39;: &#39;&#39;}}"  bindtap="changeColor4"></view>
       <view class="stars  {{flag0>=5? &#39;on&#39;: &#39;&#39;}}"  bindtap="changeColor5"></view>
   </view>
   </view>
Copy after login

JS code

Page({
  data:{
      flag:0
  },
  changeColor1:function(){
        var that = this;
        that.setData( {
            flag: 1
        });
  },
  changeColor2:function(){
        var that = this;
        that.setData( {
            flag:2
        });
    },
  changeColor3:function(){
        var that = this;
        that.setData( {
            flag: 3
        });
    },
  changeColor4:function(){
        var that = this;
        that.setData( {
            flag:4
Copy after login

Here, through the change of the value of a variable flag, Control and determine the specific value of this score [matches description].
An event function that changes the score is bound to each star to set the change in value.

WCSS code

/*星星的样式*/
.stars{
    background-image: url("http://m.dev.vd.cn/static/xcx/v1/goo/star(灰)@1.5x.png");
    width: 43rpx;
    height: 43rpx;
    background-size: 43rpx 43rpx;
    margin-left: 40rpx;
}
.on{
    background-image: url("http://m.dev.vd.cn/static/xcx/v1/goo/star@1.5x.png");
    width: 43rpx;
    height: 43rpx;
    background-size: 43rpx 43rpx;
    /*margin-left: 10px;*/
}
Copy after login


For more articles related to five-star reviews in WeChat mini programs, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template