js波浪点击按钮

12 篇文章 0 订阅

效果图:在这里插入图片描述

 <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>js波浪点击按钮</title>
        <style>
            * {
                padding: 0;
                margin: 0 auto;
            }
            body,
            html {
                height: 100%;
                display: flex;
                justify-content: center;
                align-items: center;
            }
            body {
                background: #f0f0f0;       
            }
            main {
                width: 400px;
                height: 80px;
                text-align: center;
                line-height: 80px;
                letter-spacing: 0.2em;
                font-size: 30px;
                cursor: pointer;
                position: relative;
                overflow: hidden;
                background: white;
                color: rgb(143, 141, 141);
            }
            main div {
                border-radius: 50%;
                width: 20px;
                height: 20px;
                background: rgba(0, 0, 0, 0.342);
                position: absolute;
                animation: bian 0.5s linear both 1;
            } 
            @keyframes bian {
                0% {
                    opacity: 1;
                    transform: scale(1)
                }
    
                100% {
                    opacity: 0;
                    transform: scale(8)
                }
            }
        </style>
    </head>
    
    <body>
        <main unselectable="on" onselectstart="return false;">
            点我!点我!
        </main>
    </body>
    <!-- 效果实现部分 -->
    <script>
        var main = document.querySelector('main');
        main.onmousemove = function (e) {
            var x = e.clientX - main.offsetLeft;
            var y = e.clientY - main.offsetTop;
            console.log(x, y);
            main.onclick = function () {
                var div = document.createElement('div');
                div.style.left = x + 'px';
                div.style.top = y + 'px';
                var r = Math.floor(Math.random() * 256)
                var g = Math.floor(Math.random() * 256)
                var b = Math.floor(Math.random() * 256)
                div.style.background = "rgb(" + r + ',' + g + ',' + b + ")";
                main.appendChild(div);
                setTimeout(function () {
                    main.removeChild(div);
                }, 600)
            }
        }
    </script>
    </html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值