vue模仿twitter写一个自己的博客——Button组件

twitter的Button组件实现最主要的是点击时的蓝色边框的弹出动画效果,长按时弹到最大范围且边框不动。这直接让我想到了伪类 active,通过伪元素加上伪类就很好的实现了这个效果。
BlogButton.vue

<template>
  <div :class="['btn-msg','bounce',isPrimary?'primary':'']" ref="btn" @click="handleClick">{{info}}</div>
</template>
<script lang='ts'>
import { Component, Vue, Watch, Prop } from "vue-property-decorator";
@Component({
  components: {}
})
export default class extends Vue {
  @Prop()
  private info!: string;
  @Prop()
  private type!: string;
  @Prop()
  private size!: string;
  private isPrimary: boolean = false;
  private handleClick(evt) {
    this.$emit("click", evt);
  }
  private mounted() {
    if (this.size) {
      if (!isNaN(Number(this.size))) {
        const elBtn = this.$refs.btn as HTMLElement;
        elBtn.style.width = this.size + "px";
      }
    }
    if (this.type === "primary") {
      this.isPrimary = true;
    }
  }
}
</script>
<style scoped lang="scss">
.btn-msg {
  width: 105px;
  height: 35.5px;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid $twitter-blue;
  border-radius: 100px;
  box-sizing: border-box;
  color: $twitter-blue;
  font-weight: bold;
}
:hover {
  cursor: pointer;
}
.btn-msg:hover {
  background-color: $button-hover;
}
.bounce {
  position: relative;
}
.bounce:focus {
  outline: none;
}
.bounce:after {
  content: "";
  display: block;
  position: absolute;
  top: 0px;
  left: 0px;
  right: 0px;
  bottom: 0px;
  border-radius: 100px;
  border: 0px solid $twitter-blue;
  opacity: 0.7;
  transition: all 0.1s;
}
.bounce:active:after {
  //.bounce active时 伪元素:after的样式
  opacity: 1;
  top: -5px;
  left: -5px;
  right: -5px;
  bottom: -5px;
  border-radius: 100px;
  border: 2px solid $twitter-blue;
  transition: all 0.2s;
}
.primary {
  color: #ffffff;
  background-color: #4ab3f4;
}
.primary:hover {
  background-color: $twitter-blue;
}
</style>

效果展示

在这里插入图片描述

项目地址

https://github.com/pppercyWang/twitter-blog-vue

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 基于Vue的一些资料 内容 UI组件 开发框架 实用库 服务端 辅助工具 应用实例 Demo示例 element★...
    尝了又尝阅读 1,258评论 0 1
  • UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 m...
    小姜先森o0O阅读 10,061评论 0 72
  • UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 m...
    王喂马_阅读 6,558评论 1 77
  • UI组件 element - 饿了么出品的Vue2的web UI工具套件 Vux - 基于Vue和WeUI的组...
    鲁大师666阅读 43,592评论 5 97
  • 假期前一天晚上,karry教了我“九阴真经”神功,让我内功大增,仿佛打通了全身脉络,回家后感觉一身轻松!哈哈哈。 ...
    Neverland_阅读 342评论 0 0

友情链接更多精彩内容