限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

javascript鼠标单击触发显示波纹动画特效

所属分类: 网页特效-动画效果    2024-01-26 11:56:45

javascript鼠标单击触发显示波纹动画特效 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

javascript鼠标单击触发显示波纹动画特效(共2个文件)

    • index.html
    • ripple.js

使用方法

const isTouchCapable = 'ontouchstart' in window ||
    (window.DocumentTouch && document instanceof window.DocumentTouch) ||
    navigator.maxTouchPoints > 0 ||
    window.navigator.msMaxTouchPoints > 0;
let startEv;
let endEv;
if (isTouchCapable) {
    startEv = 'touchstart';
    endEv = 'touchend';
} else {
    startEv = 'mousedown';
    endEv = 'mouseup';
}
const rippleEffect = {
    elements: ".r,button",
    color: "rgba(0,0,0,.1)",
    transitionDuration: 1,

    initialize: () => {
        const styleElement = document.createElement('style');
        styleElement.innerHTML = `
      ${rippleEffect.elements} {
        -webkit-tap-highlight-color: transparent;
        position: relative;
        cursor: pointer;
        overflow: hidden;
      }
      :root{
          --rippleColor:${rippleEffect.color}
      }
      .rs {
        position: absolute;
        background: var(--rippleColor);
        pointer-events: none;
        width: 5px;
        height: 5px;
        transform: translate(-50%, -50%);
        border-radius: 100%;
      }
      @keyframes rippleAnimation {
        0% {
          opacity: 0;
        }
        15% {
          opacity: 1;
        }
        50%, 100% {
          opacity: 1;
          width: var(--ms);
          height: var(--ms);
        }
      }
    `;
        document.head.append(styleElement);

        const elements = document.querySelectorAll(rippleEffect.elements);

        function addRippleEffect(element) {
            element.classList.add("rd");

            element.addEventListener(startEv, (event) => {
                let tchData;
                if (isTouchCapable) {
                    tchData = event.touches[0];
                } else {
                    tchData = event;
                }
                const ripple = document.createElement("div");
                const y = tchData.clientY - element.getBoundingClientRect().top;
                const x = tchData.clientX - element.getBoundingClientRect().left;
                const scaleY = Math.max(element.clientHeight - y, y) * 2.5;
                const scaleX = Math.max(element.clientWidth - x, x) * 2.5;
                const rippleSize = Math.max(scaleY, scaleX) * 3 / 2;
                const transitionDuration = Math.max(rippleSize / 1250, 0.2) + rippleEffect.transitionDuration;

                ripple.style.cssText = `
          transition: ${transitionDuration}s;
          transition-delay:.1s;
          animation: rippleAnimation forwards ${transitionDuration / 1.2}s;
          top: ${y}px;
          left: ${x}px;
          --ms: ${rippleSize}px;
        `;
                ripple.classList.add('rs');

                function removeRipple() {
                    ripple.style.background = 'transparent';
                }

                element.addEventListener(endEv, removeRipple, false);


                element.insertAdjacentElement('beforeend', ripple);
            }, false);
        }

        elements.forEach(addRippleEffect);
        const observer = new MutationObserver((mutations) => {
            mutations.forEach((mutation) => {
                mutation.addedNodes.forEach((addedNode) => {
                    if (addedNode.nodeType === 1 && addedNode.matches(rippleEffect.elements)) {
                        addRippleEffect(addedNode);
                    }
                });
            });
        });
        observer.observe(document.body, {childList: true, subtree: true});
    }
};
window.addEventListener('DOMContentLoaded', () => {
    rippleEffect.initialize()
}, false)

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 动画效果

jquery动画计数特效插件

一款动态数字递增动画插件,加载页面触发计数动画事件。
  动画效果
 8327  0

CSS3创建的不同速度滚动的视差滚动特效

一款纯css实现的视差滚动效果,背景动画由多张图片组成,而且以不同速度滚动。
  动画效果
 5110  0

CSS3软件卸载对话框鼠标跟随动画表情

一款鼠标跟随表情动画插件,当用户移动鼠标选择保留和卸载后,对话框中的表情会根据用户选择发生动态变化,非常可爱。
  动画效果
 7102  0

纯CSS3创建的渐变波浪背景动画特效

一款动态的渐变颜色背景动画效果,定时动态变换的背景渐变颜色,很平滑很好看。
  动画效果
 1214  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论