溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

小程序?qū)崿F(xiàn)星級(jí)評(píng)分效果的示例

發(fā)布時(shí)間:2020-12-21 11:26:28 來(lái)源:億速云 閱讀:149 作者:小新 欄目:移動(dòng)開(kāi)發(fā)

這篇文章給大家分享的是有關(guān)小程序?qū)崿F(xiàn)星級(jí)評(píng)分效果的示例的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧。

效果圖

小程序?qū)崿F(xiàn)星級(jí)評(píng)分效果的示例

wxml

<view >
  
    <block wx:for="{{stars}}">
      <image class="star-image" style="left: {{item*100}}rpx" src="{{key > item ?(key-item == 0.5?halfSrc:selectedSrc) : normalSrc}}">
        <view class="item" style="left:0rpx" data-key="{{item+0.5}}" bindtap="selectLeft"></view>
        <view class="item" style="left:50rpx" data-key="{{item+1}}" bindtap="selectRight"></view>
      </image>
    </block>
  <view style="margin-top:450rpx">
    <button bindtap="startRating">確認(rèn)</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,//評(píng)分
    status:'',    //0未課評(píng) 1已課評(píng)  },  /**
     * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載     */
  onLoad: function (options) {
    console.log(options.status)  },  /**
   * 點(diǎn)擊左邊,半顆星   */
  selectLeft: function (e) {
    var key = e.currentTarget.dataset.key
    if (this.data.key == 0.5 && e.currentTarget.dataset.key == 0.5) {
      //只有一顆星的時(shí)候,再次點(diǎn)擊,變?yōu)?顆
      key = 0;    }
    count = key
    this.setData({
      key: key    })

  },  /**
   * 點(diǎn)擊右邊,整顆星   */
  selectRight: function (e) {
    var key = e.currentTarget.dataset.key
    count = key
    this.setData({
      key: key    })
  },
  // 確定按鈕
  startRating: function (e) {
    wx.showModal({
      title: '分?jǐn)?shù)',
      content: "" + count,
      success: function (res) {
        if (res.confirm) {
          console.log('用戶點(diǎn)擊確定')        }
      }
    })
  }
})

感謝各位的閱讀!關(guān)于小程序?qū)崿F(xiàn)星級(jí)評(píng)分效果的示例就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI