美文网首页
小程序按钮切换效果

小程序按钮切换效果

作者: _果不其然_ | 来源:发表于2019-03-28 18:32 被阅读0次

先看一下切换效果

按钮切换.gif

附代码

WXML

  <view class='payment-inner-box'>

    <view class='alipay-module'>
      <image wx-if="{{aliPayChoose==0}}" src='../../../resource/icon/btn_normal.png' class='select-icon' bindtap='aliPaySelected'></image>
      <image wx-if="{{aliPayChoose==1}}" bindtap='aliPayUnSelected' src='../../../resource/icon/icon_selected.png' class='select-icon'></image>
      <image src='../../../resource/icon/icon_zfb.png' class='payment-icon'></image>
      <view class='payment-name'>支付宝</view>
    </view>

    <view class='wechat-payment-module'>
      <image wx-if="{{weChatPay==0}}" src='../../../resource/icon/btn_normal.png' class='select-icon' bindtap="weChatUnselected"></image>
      <image wx-if="{{weChatPay==1}}" src='../../../resource/icon/icon_selected.png' class='select-icon' bindtap='weChatSelected'></image>
      <image src='../../../resource/icon/icon_wx.png' class='payment-icon'></image>
      <view class='payment-name'>微信</view>
    </view>

  </view>

WXSS

.pay-money {
  color: rgb(243, 145, 0);
  margin-left: 3%;
  letter-spacing: 2rpx;
}
.alipay-module{
  display: flex;
  /* background: lemonchiffon; */
  width:36%;
 justify-content: space-around;
  align-items: center;
}

.payment-inner-box{
  width: 100%;
  display:flex;
  justify-content:space-around; 
  margin-top: 50%;
}
.payment-icon{
  width: 60rpx;
  height: 60rpx;
  padding-left: 3%;
}
.payment-name{
  font-size: 28rpx;
}
.wechat-payment-module{
  display: flex;
  /* background: lemonchiffon; */
  width: 36%;
  justify-content: space-around;
  align-items: center;
}
.pay-button-content{
  width: 100%;
  height: 30%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.pay-button{
  height: 80rpx;
  line-height: 76rpx;
  width: 50%;
  text-align: center;
  border: none;
  color: white;
  background: rgb(37, 37, 37);
  border-radius: 40rpx;
  font-size: 36rpx;
}
.select-icon{
  width: 48rpx;
  height: 48rpx;
}

JS

// pages/my/address/addAddress.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    aliPayChoose: 1,  //0为未选中,1为选中
    weChatPay: 0, //0为未选中,1为选中
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  
  },
  aliPaySelected: function () {
    var that = this;
    if ("weChatChoose==1") {
      that.setData({
        aliPayChoose: 1,
        weChatPay: 0
      })
    }
    // if()
  },

  weChatUnselected: function () {
    var that = this;
    if ("aliPayChoose==1") {
      that.setData({
        aliPayChoose: 0,
        weChatPay: 1,
      })
    }
  },
  aliPayUnselected: function () {
    var that = this;
    if ("weChatChoose==1") {
      that.setData({
        weChatChoose: 0,
        aliPayChoose: 1
      })
    }
  },

})

相关文章

网友评论

      本文标题:小程序按钮切换效果

      本文链接:https://www.haomeiwen.com/subject/ifucbqtx.html