vue炫彩按钮

觉得机械键盘的波纹灯光很好看,所以就设计了一个炫彩的按钮哈哈哈哈哈,记录一下。

我是把按钮封装了的,具体代码如下:

<template>
    <button :class="btnClass">
        <slot></slot>
    </button>
</template>

可以接收自定义的按钮类型。能接收两个参数,形状、大小。

<script>
  export default {
    name: 'MyButton',
    props: {
      type: {
        type: String,
        default: 'default'
      },
      size: {
        type: String,
        default: 'small'
      }
    },
    computed: {
      btnClass() {
        return `btn btn-${this.type} btn-${this.size}`;
      }
    },
  };
</script>

最后是样式部分:

<style>
@keyframes gradientAnimation {
  0% { background-position: 0% 0%; } /* 开始时的背景位置 */
  100% { background-position: 200% 0%; } /* 结束时的背景位置 */
}
.btn {
  /* 按钮的基本样式 */
  height: 30px;
  width: 80px;
  /* border-radius: 15px; */
}

.btn-default {
  /* 默认按钮样式 */
  background-color: rgb(217, 14, 14);
}

.btn-primary {
  /* 主要按钮样式 */
  background-color: rgb(11, 167, 230);
}
.btn-card {
  height: 300px;
  width: 300px;
}
.btn-color {
  /* 主要按钮样式 */
  background-image: linear-gradient(to bottom right, #d77a7a, #8aca8a, #7c7cce, skyblue, rgb(211, 211, 117), 
  #d77a7a, #8aca8a, #7c7cce, skyblue, rgb(211, 211, 117), #d77a7a); /* 初始背景色 */
  background-size: 200% 300%;
  color: #3b31c8;
  animation-name: gradientAnimation;
  animation-duration: 2s;
  animation-iteration-count: infinite;
  animation-fill-mode: forwards;
  animation-timing-function: linear;
}

/* 按钮尺寸的样式 */
.btn-small {
  height: 20px;
  width: 60px;
  border-radius: 10px;
}
.btn-large {
  height: 40px;
  width: 100px;
  border-radius: 20px;
}
</style>

最后在其他组件里使用的话就按照正常步骤来就好了。我的话是把上述代码文件都写在一个MyButton.vue组件里

然后去main.js里全局注册使用:

import MoveBlock from './components/MoveBlock.vue';


app.component('MoveBlock', MoveBlock);

 最后在其他组件中就可以正常使用了:

<my-button  
    type="color" 
    size="large"
>按钮</my-button>

最后的效果如下:

颜色会不断渐变。 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值