微信小程序实现多个按钮的颜色状态转换

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

微信小程序实现多个按钮的颜色状态转换

tingting@Wang   2020-05-16 我要评论

本文实例为大家分享了微信小程序实现按钮颜色状态转换的具体代码,供大家参考,具体内容如下

效果图片:

 index.wmxl文件

 <block wx:for="{{pres}}">
  <view class='foot_tab' data-id="{{index}}" style="{{index==id? 'color:rgb(91, 207, 97)':'color:#ddd'}}" 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?#iefix') format('embedded-opentype'),
 url('//at.alicdn.com/t/font_794639_1jyu0w9tzqh.woff') format('woff'),
 url('//at.alicdn.com/t/font_794639_1jyu0w9tzqh.ttf') format('truetype'),
 url('//at.alicdn.com/t/font_794639_1jyu0w9tzqh.svg#iconfont') format('svg');
}
 
.iconfont {
 font-family:"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';}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们