vue自己写水波纹

引入vue

html:

 

js:代码

Vue.directive('myon', {

bind(el, binding) {

el.onclick = function (e) {

// el.style.opacity = '.5';

let x = e.clientX - el.offsetLeft;

let y = e.clientY - el.offsetTop;

let left = el.offsetLeft;

let top = el.offsetTop;

console.log(x, y, left, top);


 

let span = document.createElement('span');

span.style.pointerEvents = 'none';

span.style.position = "absolute";

span.style.left = x + 'px';

span.style.top = y + 'px';

span.style.borderRadius = '50%';

let bg = binding.value || 'rgba(0,0,0,0.5)';

span.style.background = bg;

el.append(span);

let height = 0;

let width = 0;

let opacity = 1;

let timer = setInterval(() => {

height += 2;

width += 2;

opacity -= 0.03;

span.style.left = x - span.clientWidth / 2 + 'px';

span.style.top = y - span.clientHeight / 2 + 'px';

span.style.width = width + 'px'

span.style.height = height + 'px'

span.style.opacity = opacity;

if (opacity < 0) {

clearInterval(timer);

span.remove();

}

}, 10)

}

}

})

let vm = new Vue({

}).$mount('#app')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的 Vue 水波纹循环动画实现: 1. 首先,我们需要在 Vue 的 `template` 中添加一个 `div` 元素,作为容器来显示水波纹动画: ```html <template> <div class="ripple-container"> <div class="ripple"></div> </div> </template> ``` 2. 然后,在 `style` 标签中添加样式,使容器和水波纹的位置、大小、颜色等属性符合我们的需求: ```css <style> .ripple-container { position: relative; width: 200px; height: 200px; border-radius: 50%; overflow: hidden; background-color: #ccc; } .ripple { position: absolute; width: 0; height: 0; margin: auto; left: 0; right: 0; top: 0; bottom: 0; background-color: rgba(255, 255, 255, 0.7); border-radius: 50%; opacity: 0.7; animation: ripple 2s linear infinite; } @keyframes ripple { from { width: 0; height: 0; opacity: 0.7; } to { width: 400px; height: 400px; opacity: 0; } } </style> ``` 3. 最后,在 Vue 的 `script` 中添加逻辑代码,使水波纹动画循环播放: ```js <script> export default { name: 'RippleAnimation', created() { setInterval(() => { const ripple = document.querySelector('.ripple'); ripple.classList.remove('ripple'); void ripple.offsetWidth; ripple.classList.add('ripple'); }, 2000); }, }; </script> ``` 以上就是一个简单的 Vue 水波纹循环动画实现。需要注意的是,为了实现动画循环播放,我们在 `created()` 生命周期中使用 `setInterval()` 定时器来不断地重复添加、移除类名,以触发动画效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值