h5直播点击飘心效果

h5直播点击飘心效果

在这里插入图片描述
代码如下

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="apple-touch-fullscreen" content="YES" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="format-detection" content="telephone=no" />
    <title>直播点击飘心效果</title>
    <style type="text/css">
        html,
        body {
            height: 100%;
            position: relative;
            width: 100%;
        }
        
        canvas {
            display: block;
            position: absolute;
            bottom: 100px;
            right: -24px;
            z-index: 20;
            cursor: pointer;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
        }
        
        .journal-reward {
            position: absolute;
            bottom: 70px;
            right: 20px;
            height: 80px;
            width: 80px;
            display: block;
            z-index: 21;
        }
        
        .m {
            width: 100%;
            height: 100%;
            margin-left: auto;
            margin-right: auto;
            background: url("https://www.17sucai.com/preview/943199/2018-03-30/z/img/bg.jpg") no-repeat;
            background-size: 100% 100%;
        }
    </style>

    <!-- <script src="./jquery-1.8.3.min.js"> -->
    </script>



</head>

<!-- <body>
    <div id="iframe-wrap">
        <iframe id="iframe" src="https://www.17sucai.com/preview/943199/2018-03-30/z/index.html" frameborder="0" width="100%" height="586px"> 
        <div class="m"> <img src="img/reward.png" class="journal-reward"> </div>
        <canvas width="170" height="300" style="width: 100%; height: 300px;"></canvas>
    </iframe>
    </div>
</body> -->

<body>
    <div class="m"> <img src="https://www.17sucai.com/preview/943199/2018-03-30/z/img/reward.png" class="journal-reward"> </div>
    <canvas width="170" height="300" style="width: 170px; height: 300px;"></canvas>

</body>
<script>
    ! function(t, e) {
        "object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : t.BubbleHearts = e()
    }(this, function() {
        "use strict";

        function t(t, n, r) {
            var i = e.uniformDiscrete(89, 91) / 100,
                o = 1 - i,
                u = (e.uniformDiscrete(45, 60) + e.uniformDiscrete(45, 60)) / 100,
                a = function(t) {
                    return t > i ? Math.max(((1 - t) / o).toFixed(2), .1) * u : u
                },
                c = e.uniformDiscrete(-30, 30),
                f = function(t) {
                    return c
                },
                h = 10,
                s = n.width / 2 + e.uniformDiscrete(-h, h),
                d = (n.width - Math.sqrt(Math.pow(t.width, 2) + Math.pow(t.height, 2))) / 2 - h,
                l = e.uniformDiscrete(.8 * d, d) * (e.uniformDiscrete(0, 1) ? 1 : -1),
                m = e.uniformDiscrete(250, 400),
                w = function(t) {
                    return t > i ? s : s + l * Math.sin(m * (i - t) * Math.PI / 180)
                },
                v = function(e) {
                    return t.height / 2 + (n.height - t.height / 2) * e
                },
                p = e.uniformDiscrete(14, 18) / 100,
                g = function(t) {
                    return t > p ? 1 : 1 - ((p - t) / p).toFixed(2)
                };
            return function(e) {
                if (!(e >= 0)) return !0;
                r.save();
                var n = a(e),
                    i = f(e),
                    o = w(e),
                    u = v(e);
                r.translate(o, u), r.scale(n, n), r.rotate(i * Math.PI / 180), r.globalAlpha = g(e), r.drawImage(t, -t.width / 2, -t.height / 2, t.width, t.height), r.restore()
            }
        }
        var e = function(t) {
                var e = t,
                    n = Math.floor,
                    r = Math.random;
                return t.uniform = function(t, e) {
                    return t + (e - t) * r()
                }, t.uniformDiscrete = function(t, r) {
                    return t + n((r - t + 1) * e.uniform(0, 1))
                }, t
            }({}),
            n = function(t, e) {
                if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function")
            },
            r = function() {
                function t(t, e) {
                    for (var n = 0; n < e.length; n++) {
                        var r = e[n];
                        r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(t, r.key, r)
                    }
                }
                return function(e, n, r) {
                    return n && t(e.prototype, n), r && t(e, r), e
                }
            }(),
            i = window.requestAnimationFrame || window.webkitRequestAnimationFrame || function(t) {
                return setTimeout(t, 16)
            },
            o = function() {
                function o() {
                    n(this, o);
                    var t = this.canvas = document.createElement("canvas"),
                        e = this.context = t.getContext("2d"),
                        r = this._children = [],
                        u = function n() {
                            i(n), e.clearRect(0, 0, t.width, t.height);
                            for (var o = 0, u = r.length; o < u;) {
                                var a = r[o];
                                a.render.call(null, (a.timestamp + a.duration - new Date) / a.duration) ? (r.splice(o, 1), u--) : o++
                            }
                        };
                    i(u)
                }
                return r(o, [{
                    key: "bubble",
                    value: function(n) {
                        var r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : e.uniformDiscrete(2400, 3600),
                            i = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : t(n, this.canvas, this.context);
                        return this._children.push({
                            render: i,
                            duration: r,
                            timestamp: +new Date
                        }), this
                    }
                }]), o
            }();
        return o
    });
    // 图片地址在此处更换  可换成你的图片
    var assets = [
        'https://www.17sucai.com/preview/943199/2018-03-30/z/img/1.png',
        'https://www.17sucai.com/preview/943199/2018-03-30/z/img/2.png',
        'https://www.17sucai.com/preview/943199/2018-03-30/z/img/3.png',
        'https://www.17sucai.com/preview/943199/2018-03-30/z/img/4.png',
        'https://www.17sucai.com/preview/943199/2018-03-30/z/img/5.png',
    ];
    assets.forEach(function(src, index) {
        assets[index] = new Promise(function(resolve) {
            var img = new Image;
            img.onload = resolve.bind(null, img);
            img.src = src;
        });
    });

    Promise.all(assets).then(function(images) {

        var random = {
            uniform: function(min, max) {
                return min + (max - min) * Math.random();
            },
            uniformDiscrete: function(i, j) {
                return i + Math.floor((j - i + 1) * random.uniform(0, 1));
            },
        };

        var stage = new BubbleHearts();
        var canvas = stage.canvas;
        canvas.width = 170;
        canvas.height = 300;
        canvas.style['width'] = '170px';
        canvas.style['height'] = '300px';
        document.body.appendChild(canvas);
        //journal-reward 为赏桃的按钮 
        document.getElementsByClassName('journal-reward')[0].addEventListener('click', function() {
            //随机飘动
            stage.bubble(images[random.uniformDiscrete(0, images.length - 1)]);


        }, false);

    });
</script>

</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值