(编辑:jimmy 日期: 2024/11/19 浏览:2)
本文实例为大家分享了微信小程序实现按钮颜色状态转换的具体代码,供大家参考,具体内容如下
效果图片:
index.wmxl文件
<block wx:for="{{pres}}"> <view class='foot_tab' data-id="{{index}}" style="{{index==id" bindtap='changeColor'> <view class="icon"> <icon class="iconfont {{item.img_type}}"></icon> </view> <view>{{item.text}}</view> </view> </block>
index.js文件
var id; Page({ data: { pres: [{ img_type: 'icon-baomihua', text: '电影' }, { img_type:"icon-yonghu",text:'我的'}], id:0 },changeColor: function(e){ var id=e.currentTarget.dataset.id; this.setData({ id:id, }); } })
index.wxss文件
.footer { width: 100%; height: 50px; position: fixed; bottom: 0px; display: flex; flex-direction: row; justify-content: space-around; border-top: 1px solid rgb(226, 226, 226); } .foot_tab { width: 40px; height: 50px; font-size: 12px; display: flex; align-items: center; flex-direction: column; } .icon { width: 30px; height: 30px; /* background-color: #ccc; */ text-align: center; }
app.wxss
@font-face { font-family: 'iconfont'; /* project id 794639 */ src: url('//at.alicdn.com/t/font_794639_1jyu0w9tzqh.eot'); src: url('//at.alicdn.com/t/font_794639_1jyu0w9tzqh.eot"iconfont" !important; font-size:60rpx; font-style:normal; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .icon-baomihua:before{content: '\e622';} .icon-yonghu:before{content: '\e600';}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。