VUE3 + CSS实现有趣的单选框示例

3 篇文章 0 订阅

        不管是和传统的radiobox还是市面上的UI框架的radio对比。我这个选择器更加显得花里胡哨。能给页面增加不少色彩。你可以稍微改造一下就能变成一个自己的radio组件。示例中使用了element-ui的el-divider分割线组件和el-tooltip文字提示组件。完整代码如下。因为我做了自动按需引入,所以部分依赖需要自己手动引入一下。

各种表情符号等Unicode到这里拿 Unicode 字符百科

<template>
  <div style="width: 500px;">
    <el-divider>当前主题</el-divider>
    <div class="ts-flex-justify--evenly ts-admin-layout--theme">
      <el-tooltip
          effect="dark"
          placement="bottom"
          v-for="(item, index) in themeList"
          :key="index"
          :content="item.title"
      >
        <div
            class="ts-admin-theme--item"
            :class="{'is-active' : current === item.value}"
            :style="{ backgroundColor: item.color }"
            @click="changeTheme(item.value)"
        />
      </el-tooltip>
    </div>
  </div>
</template>

<script lang='ts'>

export default defineComponent({
  setup() {

    const state = reactive({
      current: 1,
      themeList: [
        {
          title: '深色主题',
          value: 1,
          color: '#262626'
        },
        {
          title: '绿色主题',
          value: 2,
          color: '#009688'
        },
        {
          title: '浅色主题',
          value: 3,
          color: '#ffffff'
        },
        {
          title: '灰色模式',
          value: 4,
          color: '#575757'
        },
      ]
    })

    const changeTheme = (value: number) => {
      state.current = value
    }

    return {
      ...toRefs(state),
      changeTheme,
    }
  }
})
</script>

<style lang="scss">
  .ts-flex-justify-between, .ts-flex-justify--evenly {
    display: flex;
    flex-direction: row;
    justify-content: space-between;

    .ts-admin-theme--item {
      width: 25px;
      height: 25px;
      border: 1px solid #c4e8e5;
      border-radius: 50%;
      cursor: pointer;
      position: relative;
      &.active {
         border-color: red;

        &::before {
           content: '\2713';
           font-size: 14px;
           color: #fff;
           position: absolute;
           top: -1px;
           left: 3px;
        }
      }
    }
  }

  .ts-admin-layout--theme {
    .ts-admin-theme--item {
      width: 60px;
      height: 60px;
      border: 5px solid #c4e8e5;
      &.is-active {
        &::before {
          content: '\1F61B';
          font-size: 48px;
          color: #0960BD;
          position: absolute;
          top: -5px;
          left: -3px;
        }
      }
    }
  }
</style>

接下来使用animate css动画库让页面动起来,显得更加的生动👇👇👇👇👇👇

// 安装库
npm install animate.css
// 引入
import 'animate.css'

注意使用animate的时候一定要加上animate__animated类,不然不起作用❗️❗️❗️❗️❗️❗️

<template>
  <div style="width: 500px;">
    <el-divider>当前主题</el-divider>
    <div class="ts-flex-justify--evenly ts-admin-layout--theme animate__animated animate__fadeInDown">
      <el-tooltip
          effect="dark"
          placement="bottom"
          v-for="(item, index) in themeList"
          :key="index"
          :content="item.title"
      >
        <div
            class="ts-admin-theme--item"
            :class="{'is-active' : current === item.value, 'animate__bounceIn' : current == item.value }"
            :style="{ backgroundColor: item.color }"
            @click="changeTheme(item.value)"
        />
      </el-tooltip>
    </div>
  </div>
</template>

我是Etc.End。如果文章对你有所帮助,能否帮我点个免费的赞和收藏😍。

👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
首先,我们可以使用Vue.js来构建控制器的UI界面,然后使用CSS3实现样式。 下面是一个简单的八方向云台控制器的示例代码: HTML: ```html <div id="app"> <div class="controller"> <div class="button up" @click="move('up')"></div> <div class="button left" @click="move('left')"></div> <div class="button right" @click="move('right')"></div> <div class="button down" @click="move('down')"></div> <div class="button up-left" @click="move('up-left')"></div> <div class="button up-right" @click="move('up-right')"></div> <div class="button down-left" @click="move('down-left')"></div> <div class="button down-right" @click="move('down-right')"></div> </div> </div> ``` CSS: ```css .controller { display: flex; flex-wrap: wrap; width: 150px; height: 150px; border: 1px solid #ccc; } .button { width: 50%; height: 50%; background-color: #fff; border: 1px solid #ccc; box-sizing: border-box; } .up { border-bottom: none; } .down { border-top: none; } .left { border-right: none; } .right { border-left: none; } .up-left { border-bottom: none; border-right: none; } .up-right { border-bottom: none; border-left: none; } .down-left { border-top: none; border-right: none; } .down-right { border-top: none; border-left: none; } ``` JS: ```js new Vue({ el: '#app', methods: { move(direction) { console.log(direction); // 在这里添加控制云台的代码 } } }); ``` 这段代码中,我们使用了flex布局来创建一个150x150像素的容器,然后在其中添加了8个按钮来实现八方向控制。每个按钮的大小为50% x 50%,并且使用CSS3的边框属性来实现不同方向的边框样式。通过Vue.js的@click事件绑定,我们可以监听每个按钮的点击事件,并在方法中处理相应的控制逻辑。 你可以根据实际需求来修改样式和控制逻辑。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Etc.End

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值