Xx-vue自定义指令实现点击水波纹涟漪效果

 更新时间:2023年07月05日 10:34:21   作者:风中凌乱的男子  
这篇文章主要为大家介绍了Xx-vue自定义指令实现点击水波纹涟漪效果,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

目录概览:

|____
|____directive
| |____waves.css
| |____waves.js
|____main.js

waves.css

.waves-ripple {
    position: absolute;
    border-radius: 100%;
    background-image: radial-gradient(circle, rgba(255, 255, 255, .35) 100%, rgba(0, 0, 0, .15) 100%);
    background-clip: padding-box;
    pointer-events: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-transform: scale(0);
    -ms-transform: scale(0);
    transform: scale(0);
    opacity: 1;
}
.waves-ripple.z-active {
    opacity: 0;
    -webkit-transform: scale(2);
    -ms-transform: scale(2);
    transform: scale(2);
    -webkit-transition: opacity 1.2s ease-out, -webkit-transform 0.6s ease-out;
    transition: opacity 1.2s ease-out, -webkit-transform 0.6s ease-out;
    transition: opacity 1.2s ease-out, transform 0.6s ease-out;
    transition: opacity 1.2s ease-out, transform 0.6s ease-out, -webkit-transform 0.6s ease-out;
}

waves.js

import './waves.css';
const vueWaves = {};
vueWaves.install = (Vue, options = {}) => {
  Vue.directive('waves', {
    bind(el, binding) {
      el.addEventListener('click', e => {
        const customOpts = Object.assign(options, binding.value);
        const opts = Object.assign({
            ele: el, // 波纹作用元素
            type: 'hit', // hit点击位置扩散center中心点扩展
            color: 'rgba(0, 0, 0, 0.15)' // 波纹颜色
          }, customOpts),
          target = opts.ele;
        if (target) {
          target.style.position = 'relative';
          target.style.overflow = 'hidden';
          const rect = target.getBoundingClientRect();
          let ripple = target.querySelector('.waves-ripple');
          if (!ripple) {
            ripple = document.createElement('span');
            ripple.className = 'waves-ripple';
            ripple.style.height = ripple.style.width = Math.max(rect.width, rect.height) + 'px';
            target.appendChild(ripple);
          } else {
            ripple.className = 'waves-ripple';
          }
          switch (opts.type) {
            case 'center':
              ripple.style.top = (rect.height / 2 - ripple.offsetHeight / 2) + 'px';
              ripple.style.left = (rect.width / 2 - ripple.offsetWidth / 2) + 'px';
              break;
            default:
              ripple.style.top = (e.pageY - rect.top - ripple.offsetHeight / 2 - document.body.scrollTop) + 'px';
              ripple.style.left = (e.pageX - rect.left - ripple.offsetWidth / 2 - document.body.scrollLeft) + 'px';
          }
          ripple.style.backgroundColor = opts.color;
          ripple.className = 'waves-ripple z-active';
          return false;
        }
      }, false);
    }
  })
};
export default vueWaves;

main.js

import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import vueWaves from './directive/waves'
Vue.use(vueWaves)
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>',
})

使用示例:

v-waves
<a class='header__crumbs--btn' @click.stop='goback' v-waves>返回</a>

以上就是Xx-vue自定义指令实现点击水波纹涟漪效果的详细内容,更多关于Xx-vue点击水波纹涟漪的资料请关注脚本之家其它相关文章!

相关文章

  • Vue3中如何使用component :is 加载组件

    Vue3中如何使用component :is 加载组件

    Monaco-editor,一个vs code 编辑器,需要将其集成到项目,这篇文章主要介绍了Vue3中如何使用component :is 加载组件,需要的朋友可以参考下
    2023-11-11
  • element多个表单校验的实现

    element多个表单校验的实现

    在项目中,经常会遇到表单检验,在这里我分享在实际项目中遇到多个表单同时进行校验以及我的解决方法,感兴趣的可以了解一下
    2021-05-05
  • Vue 3 的<Teleport>功能与用法详解

    Vue 3 的<Teleport>功能与用法详解

    <Teleport> 是 Vue 3 的一个内置组件,允许将组件的内容渲染到 DOM 中的任意位置,而不改变其逻辑结构,这篇文章主要介绍了Vue 3 的<Teleport>功能与用法详解,需要的朋友可以参考下
    2025-04-04
  • vue3上传文件、图片、视频组件实例代码

    vue3上传文件、图片、视频组件实例代码

    文件上传是一个老生常谈的话题了,这篇文章主要介绍了vue3上传文件、图片、视频组件的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下
    2026-05-05
  • Vue3中导入和使用图标库Font Awesome的实现步骤

    Vue3中导入和使用图标库Font Awesome的实现步骤

    Font Awesome 是互联网的图标库和工具包,被数百万设计师、开发人员和内容创建者使用,Font Awesome的图标非常丰富,基本涵盖你所需要的所有,本文给大家介绍了Vue3中导入和使用图标库Font Awesome的具体步骤,需要的朋友可以参考下
    2025-01-01
  • 使用vue.js在页面内组件监听scroll事件的方法

    使用vue.js在页面内组件监听scroll事件的方法

    今天小编就为大家分享一篇使用vue.js在页面内组件监听scroll事件的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-09-09
  • VUE对接deepseekAPI调用方式

    VUE对接deepseekAPI调用方式

    文章介绍了如何在Vue项目中对接DeepSeek API,包括在开放平台注册账号申请APIKey、安装axios库、创建API调用函数以及在Vue组件中调用该函数
    2025-01-01
  • vue竖向步骤条方式

    vue竖向步骤条方式

    这篇文章主要介绍了vue竖向步骤条方式,具有很好的参考价值,希望对大家有所帮助,
    2023-12-12
  • 通过Vue+axios获取接口数据的示例详解

    通过Vue+axios获取接口数据的示例详解

    这篇文章主要介绍了Vue结合axios获取笑话接口数据的示例,重点讲解axios的特性、使用方法及请求方式,演示如何通过get方法获取数据并展示,同时解决this指向问题,感兴趣的小伙伴跟着小编一起来看看吧
    2025-08-08
  • 使用vue导出excel遇到的坑及解决

    使用vue导出excel遇到的坑及解决

    这篇文章主要介绍了使用vue导出excel遇到的坑及解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-04-04

最新评论