好看的鼠标点击特效

最后更新于 2020-02-05 644 次阅读


<script type="text/javascript" src="https://lib.baomitu.com/jquery/3.3.1/jquery.min.js"></script>
<script>
    //鼠标点击特效
    onload = function() {
        var $html = document.getElementsByTagName("html")[0];
        var $body = document.getElementsByTagName("body")[0];
        var Arr=["😜","🐱","🍉","😸","😇","👌","🍕","🌹","🔥","🍌","🍍","🍄","👲","🐯","😘","🐶","🐍","🍉","🐇","🐖","🍍","🍂"];
        $html.onclick = function(e) {
            var $elem = document.createElement("b");
            $elem.style.color = "#E94F06";
            $elem.style.zIndex = 9999;
            $elem.style.position = "absolute";
            $elem.style.select = "none";
            var x = e.pageX;
            var y = e.pageY;
            $elem.style.left = (x - 10) + "px";
            $elem.style.top = (y - 20) + "px";
            clearInterval(anim);
            $elem.innerText=Arr.sort(function(){return Math.random()>0.5?-1:1;})[0];
            $elem.style.fontSize = Math.random() * 10 + 8 + "px";
            var increase = 0;
            var anim;
            setTimeout(function() {
                anim = setInterval(function() {
                    if (++increase == 150) {
                        clearInterval(anim);
                        $body.removeChild($elem);
                    }
                    $elem.style.top = y - 20 - increase + "px";
                    $elem.style.opacity = (150 - increase) / 120;
                }, 8);
            }, 70);
            $body.appendChild($elem);
        };
    };
</script>

添加到body前就可以啦

  • alipay_img
  • wechat_img
此作者没有提供个人介绍
最后更新于 2020-02-05