Vue<按键点击波纹效果>

效果图:
click.gif

起初在底层创建一个标签,通过每次点击时的位置,改变其标签的位置,通过渐变或者动画效果,使其变大。

代码如下:
<template>
  <div class="overall">
    <!-- 按键点击效果 -->
    <div class="box">
      <div
        class="btn"
        v-for="(i,index) in 4"
        :key="index"
        @mousedown="downBtn"
        @mousemove="moveBtn(index)"
        @click="clickBtn(index)"
      >
        <span>{{index}}</span>
        <div ref="cover" class="changeCover" :class="btnIndex == index?'active':''"></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      btnIndex: null,
      hoverIndex: ""
    };
  },
  methods: {
    moveBtn(index) {
      //   console.log(index);
      this.hoverIndex = index;
    },
    downBtn(e) {
      //   console.log(e);
      if (this.btnIndex == this.hoverIndex) {
        this.btnIndex = null;
      }
      let x = e.offsetX;
      let y = e.offsetY;
      this.$refs["cover"][this.hoverIndex].style.top = y + "px";
      this.$refs["cover"][this.hoverIndex].style.left = x + "px";
    },
    clickBtn(index) {
      this.btnIndex = index;
      //   this.$refs['cover'][index].sty
    }
  }
};
</script>

<style scoped>
.box {
  display: flex;
  border: 1px solid #42b983;
}
.box .btn {
  width: 80px;
  height: 50px;
  line-height: 50px;
  font-weight: bold;
  text-align: center;
  /* background: #dcf0ee; */
  color: #808080;
  cursor: pointer;
  border-right: 1px solid #42b983;
  position: relative;
  overflow: hidden;
}
.box .btn:last-child {
  border-right: none;
}
.box .btn:hover span {
  transition: 0.5s;
  color: #42b983;
}
.changeCover {
  /* transition: 0.5s; */
  width: 1px;
  height: 1px;
  position: absolute;
  z-index: -1;
  top: 0;
  left: 0;
  border-radius: 50%;
  background: rgba(92, 199, 149, 0.267);
  transform: scale(0);
}
.active {
  transition: 0.7s;
  transform: scale(200);
  /* 使用动画,点击后背景色消失 */
  /* animation: change 0.7s ease both 1; */
}
@keyframes change {
  0% {
    transform: scale(0);
    opacity: 1;
  }
  100% {
    transform: scale(200);
    opacity: 0;
  }
}
</style>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,148评论 1 32
  • 1 CALayer IOS SDK详解之CALayer(一) http://doc.okbase.net/Hell...
    Kevin_Junbaozi阅读 5,215评论 3 23
  • 【Android 动画】 动画分类补间动画(Tween动画)帧动画(Frame 动画)属性动画(Property ...
    Rtia阅读 6,260评论 1 38
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,765评论 1 45
  • GreenDao是一个轻量级且性能优良的ORM框架,本文主要简述如何使用,并作一些简单的封装。使用步骤: step...
    bruce1990阅读 535评论 0 1