前端vue3 巧妙的checkbox 选中框样式

我们 做前端页面交互效果的时候

我们会使用到 checkbox 复选框 做一些交互的效果

我是用的是 nut-ui 组件库中的 checkbox 组件

类似于这样的选中效果

假如 二选一的那种 可以 这样写 交互好看 而不是单纯的 checkbox 框

这里我就不使用 gif 图片了

大家应该都可以看懂的

我把代码 和样式放在下面

大家可以看看 都应该能看懂的

复制代码
<template>
    <div class="order-detail-type-container">
        <nut-cell-group title="购票方式">
            <nut-cell>
                <div class="purchase-type-container">
                    <div class="item" :class="{ active: !isSpeedTicket }" @click="() => {
                        isSpeedTicket = false;
                    }
                        ">
                        <div class="content">
                            <div class="title">
                                <div class="icon">
                                    <IconFont font-class-name="iconfont" class-prefix="icon" name="tuipiao" />
                                </div>
                                <div class="txt">支付宝</div>
                            </div>
                            <div class="desc">使用支付宝安全支付</div>
                        </div>
                        <div class="price">
                        </div>
                        <div class="operate">
                            <Checked class="checked-icon" color="#6551FC" />
                            <CheckNormal class="check-normal-icon" color="#6551FC" />
                        </div>
                    </div>
                </div>

            </nut-cell>
            <nut-cell>
                <div class="purchase-type-container">
                    <div class="item" :class="{ active: isSpeedTicket }" @click="() => {
                        isSpeedTicket = true;
                    }
                        ">
                        <div class="content">
                            <div class="title">
                                <div class="icon">
                                    <IconFont font-class-name="iconfont" class-prefix="icon" name="tuipiao" />
                                </div>
                                <div class="txt">支付宝</div>
                            </div>
                            <div class="desc">使用支付宝安全支付</div>
                        </div>
                        <div class="price">
                        </div>
                        <div class="operate">
                            <Checked class="checked-icon" color="#6551FC" />
                            <CheckNormal class="check-normal-icon" color="#6551FC" />
                        </div>
                    </div>
                </div>

            </nut-cell>

        </nut-cell-group>
    </div>
</template>
<script setup lang="ts">
import { IconFont, Checked, CheckNormal } from "@nutui/icons-vue-taro";
import { toRefs } from "vue";

import { ref, watch } from "vue";
const props = defineProps({
    info: Object,
});
const { info } = toRefs(props);
const isSpeedTicket = ref(false);
const emit = defineEmits(["getType"]);
watch(isSpeedTicket, (val) => {
    emit("getType", val);
});
</script>
<style lang="scss">
.order-detail-type-container {
    display: flex;
    flex-direction: column;
    font-size: 24px;

    .purchase-type-container {
        font-size: 24px;

        .item.active {
            background: #fff8f9;

            .content {
                .title {
                    .txt {
                        color: #6551FC;
                        font-size: 24px;
                    }
                }
            }

            .operate {
                .checked-icon {
                    display: block;
                }

                .check-normal-icon {
                    display: none;
                }
            }
        }

        .item {
            padding: 20px;
            border-radius: 10px;
            border: 5px solid #fff8f9;
            display: flex;
            flex-direction: row;
            // width: 100%;

            .content {
                flex: 1;
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: flex-start;

                .title {
                    display: flex;
                    flex-direction: row;

                    .icon {
                        display: flex;
                        flex-direction: column;
                        align-items: center;
                        justify-content: center;
                        background: linear-gradient(to right, #875CFD,
                                #6551FC);
                        height: 38px;
                        width: 38px;
                        border-radius: 50px;
                        margin-right: 15px;

                        .iconfont {
                            font-size: 24px;
                            color: #ffffff;
                        }
                    }

                    .txt {
                        font-weight: 500;
                        color: #15181d;
                        font-size: 32px;
                    }
                }

                .desc {
                    margin-top: 15px;
                    color: #858a99;
                    font-size: 22px;
                }
            }

            .price {
                display: flex;
                flex-direction: column;
                align-items: flex-end;
                justify-content: center;

                .title {
                    display: flex;
                    height: 35px;
                    flex-direction: row;
                }

                .desc {
                    color: #858a99;
                    font-size: 22px;
                }
            }

            .operate {
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;
                width: 80px;

                .checked-icon {
                    display: none;
                }

                .check-normal-icon {
                    display: block;
                }
            }
        }
    }
}
</style>
相关推荐
巧克力芋泥包11 小时前
前端使用阿里云图形验证码;并且与安卓进行交互
android·前端·阿里云
G***E31612 小时前
前端GraphQLAPI
前端
lumi.12 小时前
Vue + Element Plus 实现AI文档解析与问答功能(含详细注释+核心逻辑解析)
前端·javascript·vue.js·人工智能
z***I39412 小时前
VueGraphQLAPI
前端
粉末的沉淀14 小时前
css:制作带边框的气泡框
前端·javascript·css
N***738515 小时前
Vue网络编程详解
前端·javascript·vue.js
e***716715 小时前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
程序猿小蒜15 小时前
基于springboot的的学生干部管理系统开发与设计
java·前端·spring boot·后端·spring
银空飞羽15 小时前
让Trae CN SOLO自主发挥,看看能做出一个什么样的项目
前端·人工智能·trae
Eshine、16 小时前
解决前端项目中,浏览器无法正常加载带.gz名称的文件
前端·vue3·.gz·.gz名称的js文件无法被加载