微信小程序自定义checkbox/button

自定义checkbox或button,任意设置图片和文字,点击改变背景和文字,有抖动效果。如下图的接收、HEX、清空、更多。
在这里插入图片描述
具体代码如下:

1、custom_button.js

Component({

    /**
     * 组件的属性列表
     */
    properties: {
        label:String,
        img:String,
    },

    /**
     * 组件的初始数据
     */
    data: {
    },

    //组件初始化
    attached(){
    },

    /**
     * 组件的方法列表
     */
    methods: {
        // handleTap(){
        //     console.log("handleTap2="+this.data.clicked)
        //     this.triggerEvent('backDataTap', this.data.checked)
        // },
    }
})

2、custom_button.json

{
    "component": true,
    "usingComponents": {}
}

3、custom_button.wxml

<button class="button" style="height: 90rpx;width:150rpx" hover-start-time="0" hover-class="button-press" > 
    <image style="height: 45rpx;width: 45rpx;" src='{{img}}'></image>
    <text style="color: var(--color2); font-size: 20rpx">{{label}}</text>
</button>

4、custom_button.wxss

.button{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #FFFFFF00;
    padding: 0;
    height: 100%;
    border-radius: 0%
}

/*按下后的样式*/
.button-press{
    padding-top: 10rpx;
}

使用方法:通过设置按下前后的图片,显示不同的效果。

    <view class="toolBar_container">    
        <custom_button label="接收" img="{{isCheckScroll==false ? '/img/checkOff.png' : '/img/checkOn.png'}}" bindtap="checkScroll" />
        <custom_button label="HEX" img="{{isCheckRecHex==false ? '/img/checkOff.png' : '/img/checkOn.png'}}" bindtap="checkRecHex" />
        <custom_button label="清空" img="/img/clear.png" bindtap="btClear" />
        <custom_button label="{{isButtonMore==false ? '更多' : '收起'}}" img="{{isButtonMore==false ? '/img/moreOff.png' : '/img/moreOn.png'}}" bindtap="btMore" />
    </view>

扫码可看到具体的效果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值