jq实现双击点赞效果

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .ver-video-cover {
            position: fixed;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            opacity: 0;
            z-index: 11;
        }
    </style>
</head>
<body>
<div class="ver-video-cover"></div>
</body>
<script type="text/javascript" src="https://lib.baomitu.com/fastclick/1.0.6/fastclick.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
    $(function() {
        FastClick.attach(document.body);
        // 获取随机数
        function verRandomNum(minNum, maxNum) {
            switch (arguments.length) {
                case 1:
                    return parseInt(Math.random() * minNum + 1, 10);
                    break;
                case 2:
                    return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
                    break;
                default:
                    return 0;
                    break;
            }
        }

        // 点赞动效
        function likeAnimation(e) {
            var randomDeg = verRandomNum(0, 45);
            var $Ani = $('<img class="ver-my-zan" src="https://v.cmcc-cs.cn/ngvlcs/app/img/ver-like1.png">');
            var x = e.pageX, y = e.pageY;//获取鼠标点击的位置坐标
            $Ani.css({
                "z-index": 30,
                "top": y - 30,
                "left": x - 30,
                "position": "absolute",
                "width": '60',
                "height": '60',
                "transform": "rotate(-" + randomDeg + "deg)"
            });
            $("body").append($Ani);
            $Ani.animate({
                "top": y - 180,
                "width": '120',
                "height": '120',
                "opacity": 0
            }, 1000, function () {
                $Ani.remove();
            });//设置动画

        }
        var verClickNum = 1, clickTimer = null, lastClickTime = 0;
        $("body").on("click", ".ver-video-cover,.ver-my-zan", function (e) {
            var nowTime = new Date().getTime();
            if (nowTime - lastClickTime < 300) {
                /*双击*/
                verClickNum++;
                lastClickTime = 0;
                clickTimer && clearTimeout(clickTimer);
                likeAnimation(e)
            } else {
                /*单击*/
                lastClickTime = nowTime;
                clickTimer = setTimeout(function () {
                    if(verClickNum > 1){
                        verClickNum = 1;
                        return;
                    }else {

                    }
                }, 300);
            }

        });

    });

</script>
</html>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值