[前端] 分享四个常用炫彩按钮组件 样式美观 动画丝滑 一(附代码)

[前端] 分享四个常用炫彩按钮组件 样式美观 动画丝滑 一(附代码)

在这里插入图片描述

指路:[前端] 分享三个常用简约按钮组件 样式美观 动画丝滑 一(附代码)

这两天学前端的css技术。发现很强大。许多我认为只有js能解决的问题都可以用css解决。为了进行练习,手写了四个按钮,并且封装成组件。动画过度丝滑、颜色协调。

注意: 代码中出现的事件只为测试示例,需要根据实际需求修改

普通炫彩按钮

效果

在这里插入图片描述

在这里插入图片描述

代码:

<template>
  <div class="colorful-button" @click="handleClick">
    <span>
      <slot>按钮</slot>
    </span>
  </div>
</template>

<script>
export default {
  data() {
    return {
      color: 'red',
    }
  },
  methods: {
    handleClick() {
      this.$emit('click')
    },
  },
}
</script>

<style scope>
.colorful-button {
  background-image: linear-gradient(35deg, #b8cbb8 0%, #b8cbb8 0%, #b465da 0%, #cf6cc9 33%, #ee609c 66%, #ee609c 100%);
  /* background-size: 400% 400%; */
  display: flex;
  justify-content: center;
  align-items: center;
  width: 200px;
  height: 50px;
  border-radius: 10px;
  padding: 3px;
  box-shadow: 0 5px 10px -5px #ef03f8;
}
.colorful-button > span {
  color: white;
  font-size: 16px;
  font-weight: 600;
  text-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
  background: black;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.colorful-button:hover > span {
  color: #eee;
  background: none;
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
}

.colorful-button:hover {
  transform: scale(1.1);
}
</style>

会员按钮

效果

123

在这里插入图片描述

<template>
  <div class="pro-button" @click="handleClick">
    <slot>按钮</slot>
  </div>
</template>

<script>
export default {
  methods: {
    handleClick() {
      this.$emit('click')
    },
  },
}
</script>

<style>
.pro-button {
  width: 200px;
  height: 50px;
  line-height: 50px;
  text-align: center;
  font-weight: bold;
  border: 1px solid #333;
  cursor: pointer;
  background: linear-gradient(15deg, #880088, #aa2068, #cc3f47, #de6f3d, #f09f33, #de6f3d, #cc3f47, #aa2068, #880088) no-repeat;
  background-size: 300%;
  background-position: left center;
  color: hsl(59, 95%, 49%);
  box-shadow: 0 0 5px #333;
  border-radius: 25px;
  font-size: 18px;
  transition: all 0.5s;
}

.pro-button:hover {
  background-size: 320%;
  background-color: #333;
  color: #fff;
  box-shadow: 0 0 5px #fff;
  background-position: right center;
  transform: scale(1.1);
}
</style>

登录/登出按钮1

SVG图在鼠标放入时缩小,直到消失。在鼠标移出时恢复。适合放在空间紧张的地方

效果

321

在这里插入图片描述

<template>
  <div class="login-button" @click="handleClick">
    <div class="arrow">
      <svg
        t="1726728957001"
        class="icon"
        viewBox="0 0 1024 1024"
        version="1.1"
        xmlns="http://www.w3.org/2000/svg"
        p-id="5938"
        width="200"
        height="200"
      >
        <path
          d="M409.002667 469.333333L300.8 361.130667 361.130667 300.8l211.2 211.2-211.2 211.2-60.330667-60.330667L409.002667 554.666667H128v-85.333334h281.002667zM469.333333 128h341.333334c46.933333 0 85.333333 38.4 85.333333 85.333333v597.333334c0 46.933333-38.4 85.333333-85.333333 85.333333h-341.333334v-85.333333h341.333334V213.333333h-341.333334V128z"
          fill="#000000"
          p-id="5939"
        ></path>
      </svg>
    </div>
    <div class="slot">
      <slot>按钮</slot>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {}
  },
  methods: {
    handleClick() {
      this.$emit('click')
    },
  },
}
</script>

<style scoped>
.login-button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 50px;
  height: 50px;
  background-color: rgb(47, 255, 64);
  border-radius: 25px;
  box-shadow: 0 0 5px rgb(47, 255, 64);
  transition: all 0.5s ease;
  cursor: pointer;
}

.login-button .arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  transition: all 0.2s ease;
}

.login-button .arrow svg {
  width: 60%;
  height: 60%;
}

.login-button .arrow svg path {
  fill: white;
}

.login-button .slot {
  display: none;
  /* 透明 */
  opacity: 0;
  width: 0%;
  opacity: 0;
  color: white;
  font-size: 0px;
  transition: all 0.2s ease;
  transition-delay: 0.3s;
}

.login-button:hover .slot {
  display: flex;
  opacity: 1;
  width: 100%;
  font-size: 18px;
  font-weight: bold;
  text-shadow: 0 0 5px white;
  overflow: hidden;
  white-space: nowrap;
  text-align: center;
  align-items: center;
  justify-content: center;
}

.login-button:hover .arrow {
  width: 0%;
}

.login-button:hover {
  width: 160px;
}
</style>

登录/登出按钮2

SVG图保持不变,适合放在界面空间较大的地方

效果

asd

在这里插入图片描述

<template>
  <div class="logout-button" @click="handleClick">
    <div class="arrow">
      <svg
        t="1726731738552"
        class="icon"
        viewBox="0 0 1024 1024"
        version="1.1"
        xmlns="http://www.w3.org/2000/svg"
        p-id="6907"
        width="200"
        height="200"
      >
        <path
          d="M835.669333 554.666667h-473.173333A42.453333 42.453333 0 0 1 320 512a42.666667 42.666667 0 0 1 42.474667-42.666667h473.173333l-161.813333-161.834666a42.666667 42.666667 0 0 1 60.330666-60.330667l234.666667 234.666667a42.666667 42.666667 0 0 1 0 60.330666l-234.666667 234.666667a42.666667 42.666667 0 0 1-60.330666-60.330667L835.669333 554.666667zM554.666667 42.666667a42.666667 42.666667 0 1 1 0 85.333333H149.525333C137.578667 128 128 137.578667 128 149.482667v725.034666C128 886.4 137.6 896 149.525333 896H554.666667a42.666667 42.666667 0 1 1 0 85.333333H149.525333A106.816 106.816 0 0 1 42.666667 874.517333V149.482667A106.773333 106.773333 0 0 1 149.525333 42.666667H554.666667z"
          p-id="6908"
        ></path>
      </svg>
    </div>
    <div class="slot">
      <slot>按钮</slot>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {}
  },
  methods: {
    handleClick() {
      this.$emit('click')
    },
  },
}
</script>

<style scoped>
.logout-button .arrow svg {
  width: 50%;
  height: 50%;
}

.logout-button .arrow svg path {
  fill: white;
}

.logout-button {
  position: relative;

  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 50px;
  height: 50px;
  overflow: hidden;
  cursor: pointer;

  background-color: rgb(255, 64, 64);
  border-radius: 25px;
  box-shadow: 0 0 5px 1px rgb(255, 64, 64);

  transition: all 0.5s ease;
}

.logout-button .arrow {
  position: relative;
  left: 0;
  top: 0%;
  width: 50px;
  height: 50px;

  display: flex;
  align-items: center;
  justify-content: center;
}

.logout-button .slot {
  position: absolute;
  left: 50px;

  display: flex;
  align-items: center;
  justify-content: center;

  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  width: 0;
  transition: all 0.5s ease;
}

.logout-button:hover {
  width: 200px;
}

.logout-button:hover .slot {
  opacity: 1;
  width: 70%;
  color: white;
  font-size: 18px;
  font-weight: bold;
  text-shadow: 0 0 5px white;
  overflow: hidden;
  white-space: nowrap;
}
</style>

总结

使用之前:

  1. 了解vue中关于组件的说明。了解vue中组件的引用方式。
  2. 了解vue中各个部分的作用,需要对vue内置功能进行学习。
  3. 对按钮中示例js进行修改,没必要传递事件给上级组件。
  4. 需要在使用按钮的文件中添加相关引用,并且引入组件。
  5. 根据项目需求进行修改

希望大家使用顺利,一起进步,一起学习。

相关资源: 免费 前端资源 纯css实现的4个炫彩vue组件按钮 动画丝滑 样式美观 使用方便 支持拓展 使用HTML 无JavaScript

系列文章:[前端] 分享三个常用简约按钮组件 样式美观 动画丝滑 一(附代码)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

飛_

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

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

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

打赏作者

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

抵扣说明:

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

余额充值