首页 > 其他分享 >点击水波纹效果 点击ripple效果

点击水波纹效果 点击ripple效果

时间:2023-06-09 15:11:42浏览次数:32  
标签:水波纹 function style option var 点击 ripple

1.创建 ripple.js 复制以下代码即可

!function (t, e) {
    "use strict";
    if (void 0 === n || !n) var n = function (t) {
        var e = {
            opacity: .5, speed: .6, bgColor: "#ffffff", cursor: !0
        };
        this.option = this.extend(t, e), this.isltIE9() || this.init()
    };
    n.prototype = {
        createEle: function (t) {
            return e.createElement(t)
        },
        extend: function (t, e) {
            var n = JSON.parse(JSON.stringify(e)); for (var i in t) n[i] = t[i]; return n
        },
        isltIE9: function () {
            return !!/MSIE6.0|MSIE7.0|MSIE8.0|MSIE9.0/i.test(navigator.userAgent.split(";")[1].replace(/[ ]/g, ""))
        },
        getPosition: function (t) {
            var e = this.getBoundingClientRect(), n = Math.max(e.width, e.height); return {
                range: n, x: t.clientX - e.left - n / 2, y: t.clientY - e.top - n / 2
            }
        },
        addEvent: function () {
            for (var t = this, n = 0; n < this.elements.length; n++)
                "boolean" == typeof t.option.cursor && t.option.cursor && (this.elements[n].style.cursor = "pointer"),
                    this.elements[n].addEventListener("mousedown", function (n) {
                        n.stopPropagation();
                        var i = t.getPosition.call(this, n),
                            o = e.createElement("span");
                        o.className = "ripple",
                            o.style.top = i.y + "px",
                            o.style.left = i.x + "px",
                            o.style.width = i.range + "px",
                            o.style.height = i.range + "px",
                            o.style.animationDuration = t.option.speed + "s",
                            o.style.background = t.option.bgColor,
                            o.style.opacity = t.option.opacity,
                            o.addEventListener("animationend", function () {
                                this.parentNode.removeChild(this)
                            }, !1),
                            this.appendChild(o)
                    }, !1)
        }
    }, n.prototype.init = function () {
        var n = this;
        t.onload = function () {
            n.elements = e.querySelectorAll('[data-ripple="ripple"]'), n.addEvent()
        }
    }, t.Ripple = n
}(window, document);

2.创建 index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
  <script data-static="2.0" data-onmap="3.0" data-dev="true" src="/f/js/Spatial.bjs?&v=3.0"></script>
  <script src="./ripple.js"></script>
  <style>
    [data-ripple="ripple"] {
        position: relative;
        overflow: hidden;
        -webkit-user-select: none;
        -moz-webkit-user-select:none;
        -ms-user-select:none;
    }

    [data-ripple="ripple"] .ripple {
        display: block;    
        width: 100%;
        height: 100%;
        border-radius:100%;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 888;    
        background: rgba(157, 97, 97, 0.5);
        pointer-events: none;
        transform: scale(0);
        animation: ripple .6s 0s linear;
    }
    @keyframes ripple {
        100% {
            opacity: 0;
            transform: scale(2.5);
        }
    }

    .aaa{
      width: 400px;
      height: 400px;
    }
  </style>
</head>
<body>
  <div class="aaa" data-ripple="ripple"></div>
</body>
<script type="text/javascript">
  new Ripple({
      opacity : 0.6,  //水波纹透明度
      speed : 1,      //水波纹扩散速度
      bgColor : "#ff0", //水波纹颜色
      cursor : true  //是否显示手型指针
  })
</script>
</html>

 

标签:水波纹,function,style,option,var,点击,ripple
From: https://www.cnblogs.com/zgfs/p/17469252.html

相关文章

  • 直播商城源码,点击复制功能和长按复制功能
    直播商城源码,点击复制功能和长按复制功能一、点击复制+长按复制效果 index.wxml 注意:data-title=我是被复制的文本内容<textselectable="true">我是被复制的文本内容/text><viewbindtap="copyBtn"data-title="{{title}}">复制</view>index.js  //不使用封装方法  ......
  • 【漫画详解】用iframe障眼法,骗取用户点击
    做过Web开发的朋友曾经都有过这么个念头:在自己的页面里内嵌一个其他网站的网页,然后可以用脚本去获取他们页面里的信息,甚至可以。。。显然,有这么好的事也肯定轮不到你来尝了:)一个叫沙箱模型的东西被发明出来,就是防止有这种想法的人搞破坏。。。所以现在的我们只能远观,不可亵......
  • jquery Mobile点击显示加载等待效果
    点击某个按钮或链接时,触发等待加载效果:<script><!--$(document).bind("mobileinit",function(){});$(function(){//默认设置,一个小圈圈在转$('#default').live('tap',function(){$.mobile.loadingMessageTe......
  • jquery 实现 点击按钮后倒计时效果,多用于实现发送手机验证码、邮箱验证码
    <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title></title>......
  • 原生实现按钮点击涟漪效果
    效果实现思路一个按钮,点击实现涟漪效果;按钮有底色,他的涟漪效果需要一个在它上面的蒙版实现(定位);蒙版设置动画效果,这个动画效果触发的条件是点击;点击效果只有很短的时间,所以,点击之后触发动画,一定时间后关闭动画,换个思路,我们无需控制动画的触发和暂停,但是可以控制蒙版元素的......
  • 模拟点击系统按键
    privatevoidsendEvent(intaction,intcode){longwhen=SystemClock.uptimeMillis();finalKeyEventev=newKeyEvent(when,when,action,code,0/*repeat*/,0/*metaState*/,KeyCharacterMap.VIRTUAL_KEYBOARD,0/*scancode*/,......
  • css实现点击按钮进行右移的动画
    html页面:<divv-if="hideTip"id="tipsButton">   <el-tooltipclass="item"effect="dark"content="打印表格"placement="top">    <el-buttonicon="el-icon-printer"style=......
  • ECharts点击横坐标事件实现超链接跳转
    需求:微博排行榜,横坐标展示出了微博对应的id,现在需要通过点击横坐标来实现跳转到对应的微博页面。设置横坐标中的triggerEvent属性为true;xAxis:{...triggerEvent:true,...},添加on点击事件。thisChart.on("click",function(params){window.location.......
  • qt——不写鼠标事件,获取鼠标点击窗口后的坐标位置
               ......
  • win11鼠标能动但是无法点击怎么办 win11鼠标能动但是无法点击解决方案(WSG实测可以)
    win11用户在使用电脑的时候遇到了鼠标能动但是无法点击的情况,像这种情况要怎么办呢?你先按住ctrl+alt+delete这组快捷键,然后打开任务管理器,接着选择运行新任务,输入explorer.exe,之后系统就会自动刷新桌面缓存,这个时候应该问题就解决了。如果不行的话,应该是鼠标驱动出问题了,建议大家......