微信小程序?qū)崿F(xiàn)星星評(píng)價(jià)效果
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)星星評(píng)價(jià)效果的具體代碼,供大家參考,具體內(nèi)容如下
代碼實(shí)現(xiàn)
wxml文件
<!--pages/evaluatepage/evaluatepage.wxml--> <view class='container'> <view class='evaluate_contant'> <!--外層循環(huán)控制有幾個(gè)評(píng)價(jià)條目 --> <block wx:for='{{evaluate_contant}}' wx:key='' wx:for-index='idx'> <view class='evaluate_item'> <view class='evaluate_title'>{{item}}</view> <!--星星評(píng)價(jià) --> <view class='evaluate_box'> <!--內(nèi)層循環(huán)展示每個(gè)評(píng)價(jià)條目的星星 --> <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: ['評(píng)價(jià)條目一', '評(píng)價(jià)條目二', '評(píng)價(jià)條目三',], 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('評(píng)價(jià)得分' + this.data.scores) }, //點(diǎn)擊左邊,半顆星 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 }) }, //點(diǎn)擊右邊,整顆星 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
/*評(píng)價(jià)區(qū)域 */ .container .evaluate_contant .evaluate_item { font-size: 30rpx; color: gray; margin-left: 20rpx; margin-top: 30rpx; } /*評(píng)價(jià)標(biāo)題 */ .container .evaluate_contant .evaluate_item .evaluate_title { display: inline-block; } /*評(píng)價(jià)盒子 */ .container .evaluate_contant .evaluate_item .evaluate_box { position: absolute; left: 220rpx; width: 100%; display: inline-block; } /*星星評(píng)價(jià)的每個(gè)圖片 */ .container .evaluate_contant .evaluate_item .evaluate_box .star-image { position: absolute; width: 40rpx; height: 40rpx; src: "../../images/no-star.png"; } /*星星的左邊和右邊區(qū)域<點(diǎn)擊左邊半個(gè)星星,點(diǎn)擊右邊整個(gè)星星> */ .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; }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript面向?qū)ο罂焖偃腴T(mén)實(shí)例
這篇文章主要介紹了javascript面向?qū)ο罂焖偃腴T(mén)實(shí)例,以一個(gè)簡(jiǎn)單實(shí)例分析了javascript面向?qū)ο蟮闹袑?duì)象的定義與使用技巧,需要的朋友可以參考下2015-01-01js/jQuery簡(jiǎn)單實(shí)現(xiàn)選項(xiàng)卡功能
本篇文章主要是對(duì)js/jQuery簡(jiǎn)單實(shí)現(xiàn)選項(xiàng)卡功能的示例代碼進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-01-01uniapp中canvas繪制圖片內(nèi)容空白報(bào)錯(cuò)的原因及解決
最近有個(gè)需求就是要用canvas畫(huà)個(gè)分享的海報(bào),所以這里總結(jié)下,這篇文章主要給大家介紹了關(guān)于uniapp中canvas繪制圖片內(nèi)容空白報(bào)錯(cuò)的原因及解決方法,需要的朋友可以參考下2023-09-09全面了解函數(shù)聲明與函數(shù)表達(dá)式、變量提升
下面小編就為大家?guī)?lái)一篇全面了解函數(shù)聲明與函數(shù)表達(dá)式、變量提升。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08基于JavaScript實(shí)現(xiàn)移動(dòng)端點(diǎn)擊圖片查看大圖點(diǎn)擊大圖隱藏
最近接了個(gè)項(xiàng)目,項(xiàng)目需求是這樣的,當(dāng)點(diǎn)擊圖片查看圖片,再次點(diǎn)擊大圖被隱藏,在移動(dòng)端用的比較多,因?yàn)橐苿?dòng)端屏幕小,需要查看大圖。具體代碼實(shí)現(xiàn)過(guò)程本文給大家介紹,需要的朋友可以參考下2015-11-11javascript中break,continue和return語(yǔ)句用法小結(jié)
break,continue和return這三個(gè)語(yǔ)句的用法新手們經(jīng)常弄混淆,至少在我學(xué)習(xí)c語(yǔ)言的時(shí)候經(jīng)常把它們的用法給搞錯(cuò)。不過(guò)現(xiàn)在好了,我已徹底搞清楚它們之間的用法2012-05-05JavaScript實(shí)現(xiàn)煙花和福字特效
這篇文章主要介紹了利用JavaScript實(shí)現(xiàn)放煙花特效和用字符“$”繪制“?!弊郑闹械氖纠a簡(jiǎn)潔易懂,感興趣的小伙伴可以學(xué)習(xí)一下2022-01-01