search
HomeWeChat AppletMini Program DevelopmentHow to achieve star rating effect in mini program? (code example)

The content of this article is to introduce how small programs can achieve star rating effects? (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Rendering

How to achieve star rating effect in mini program? (code example)

##wxml

##

<view>
  
    <block>
      <image> item ?(key-item == 0.5?halfSrc:selectedSrc) : normalSrc}}">
        <view></view>
        <view></view>
      </image>
    </block>
  <view>
    <button>确认</button>
  </view></view>

wxss

.star-image{
  position: absolute;
  top: 50rpx;
  margin-left: 100rpx;
  width: 100rpx;
  height: 100rpx;
  src: "/images/icon/star-no.png";
}.item{
  position: absolute;
  top: 50rpx;
  width: 100rpx;
  height: 100rpx;
}

js

//index.js
var app = getApp()
var count = 0;
Page({
  data: {
    stars: [0, 1, 2, 3, 4],
    normalSrc: '/images/icon/star-no.png',
    selectedSrc: '/images/icon/star-full.png',
    halfSrc: '/images/icon/star-half.png',
    key: 0,//评分
    status:'',    //0未课评 1已课评  },  /**
     * 生命周期函数--监听页面加载     */
  onLoad: function (options) {
    console.log(options.status)  },  /**
   * 点击左边,半颗星   */
  selectLeft: function (e) {
    var key = e.currentTarget.dataset.key
    if (this.data.key == 0.5 && e.currentTarget.dataset.key == 0.5) {
      //只有一颗星的时候,再次点击,变为0颗
      key = 0;    }
    count = key
    this.setData({
      key: key    })

  },  /**
   * 点击右边,整颗星   */
  selectRight: function (e) {
    var key = e.currentTarget.dataset.key
    count = key
    this.setData({
      key: key    })
  },
  // 确定按钮
  startRating: function (e) {
    wx.showModal({
      title: '分数',
      content: "" + count,
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')        }
      }
    })
  }
})

Reprinted from the star rating of the mini program component

The above is the detailed content of How to achieve star rating effect in mini program? (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools