利用CSS3动画属性,以及transition 标签控制样式opacity值实现淡入淡出效果,从而实现类似水波纹的动态效果。
具体实现效果如图:
demo代码如下:
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>录音效果title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">script>
head>
<style>
body{
background-color: #333333;
text-align: center;
}
.content{
height:10px;
width:100px;
border-radius:100%;
position: relative;
margin:200px auto;
}
.fade-enter {
opacity: 0;
}
.fade-enter-active {
transition: opacity 1s;
}
.fade-leave-to {
opacity: 0;
}
.fade-leave-active {
transition: opacity 3s;
}
.dot {
animation: sploosh 1.5s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.dot2 {
animation: sploosh2 1.5s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.dot3 {
animation: sploosh3 1.5s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.dot,
.dot2,
.dot3 {
height: 100px;
width: 100px;
font-size: 20px;
color: #fff;
line-height: 100px;
text-align: center;
border-radius: 100%;
position: absolute;
z-index: 20;
animation-iteration-count: infinite;
background: transparent;
}
.dot-start {
height: 100px;
width: 100px;
font-size: 20px;
color: #fff;
line-height: 100px;
text-align: center;
border-radius: 100%;
position: absolute;
z-index: 10;
animation-iteration-count: infinite;
background: transparent;
background-color: rgba(255, 220, 1, 0.7);
}
.dot30 {
height: 100px;
width: 100px;
font-size: 20px;
color: #fff;
line-height: 100px;
text-align: center;
border-radius: 100%;
position: absolute;
z-index: 30;
animation-iteration-count: infinite;
background: transparent;
background-color: rgba(255, 220, 1, 0.7);
}
@keyframes sploosh {
0% {
box-shadow: 0 0 0 0px rgba(255, 220, 1, 0.7);
background: rgba(255, 220, 1, 0.7);
}
100% {
box-shadow: 0 0 0 30px rgba(255, 220, 1, 0);
background: rgba(255, 220, 1, 0);
}
}
@keyframes sploosh2 {
0% {
box-shadow: 0 0 0 0px rgba(255, 220, 1, 0.7);
background: rgba(255, 220, 1, 0.7);
}
100% {
box-shadow: 0 0 0 20px rgba(255, 220, 1, 0);
background: rgba(255, 220, 1, 0.3);
}
}
@keyframes sploosh3 {
0% {
box-shadow: 0 0 0 0px rgba(255, 220, 1, 0.7);
background: rgba(255, 220, 1, 0.7);
}
100% {
box-shadow: 0 0 0 10px rgba(255, 220, 1, 0);
background: rgba(255, 220, 1, 1);
}
}
style>
<body>
<div id="app">
<div class="content">
<transition name="fade">
<div v-if="show">
<div v-if="show" class="dot">
<div class="dot2">
<div id="div3" class="dot3">div>
div>
div>
div>
transition>
<div v-if="show" class="dot30">
正在录音
div>
<div class="dot-start">
div>
div>
<button v-if="show" @click="startRecord">停止录音button>
<button v-if="!show" @click="endRecord">开始录音button>
div>
<script>
new Vue({
el: '#app',
data() {
return {
show: false,
show1: false
};
},
methods: {
startRecord(){
this.show=false;
this.show1=true;
},
endRecord(){
this.show=true;
this.show1=false;
}
}
})
script>
body>
html>