多次点击div动画重新开始渲染

本文介绍了一种使用Vue.js实现的动态动画提示效果,通过监听点击事件动态调整元素的动画时长,实现流畅的动画过渡。文章详细展示了如何利用JavaScript和CSS动画属性来创建自定义动画效果。

<template>

<div class="box">

<div class="divtop" @click="showtip">

<div class="divtip tip1">1</div>

<div class="divtip tip2">2</div>

</div>

<div class="divtop" @click="showtip">

<div class="divtip tip1">1</div>

<div class="divtip tip2">2</div>

</div>

<div class="divtop" @click="showtip">

<div class="divtip tip1">1</div>

<div class="divtip tip2">2</div>

</div>

</div>

</template>

<script type="text/javascript">

export default{

name: 'resource',

data () {

return{

testTime:0,

}

},

methods: {

showtip (e) {

let list = Array.prototype.slice.call(e.srcElement.getElementsByClassName('divtip'));

let newTime = (new Date).getTime();

list.forEach(i => {

if(i.style.animationDuration){

let a = (newTime - this.testTime)/1000;

i.style.animationDuration =parseFloat(i.style.animationDuration) + a +'s';

}else{

i.style.animation ='showtime 2.5s';

}

i.addEventListener("animationend",function(e){

i.style.animation ='';

});

});

this.testTime = newTime;

},

 

hidetip () {

 

}

}

};

</script>

<style type="text/less" lang="less">

.box{

display: flex;

}

.divtop{

width: 90px;

height: 90px;

border: 1px solid red;

border-radius: 50%;

margin: 15px;

background: green;

position: relative;

@keyframes showtime{

0%{

opacity: 0;

}

5%{

opacity: 1;

}

95%{

opacity: 1;

}

100%{

opacity: 0;

}

}

 

& .divtip{

width: 20px;

height: 20px;

border: 1px solid gray;

border-radius: 50%;

opacity: 0;

position: absolute;

bottom: 0;

right: 0;

transform: rotate(0edge);

&:hover{

opacity: 1;

}

}

& .tip1{

bottom: -1rem;

right: -1rem;

transition-delay:0.02s;

}

& .tip2{

bottom: 2rem;

right: -1rem;

transition-delay:0.04s;

}

}

 

@keyframes menuanimation {

10%{

z-index: 1;

transform: scale(1);

}

90%{

z-index: 0;

transform: scale(0);

}

}

</style>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值