js实现直播点击飘心效果
作者:施主请别摸老衲的脸 发布时间:2024-02-24 18:29:22
标签:js,直播,飘心
本文实例为大家分享了js实现直播点击飘心效果的具体代码,供大家参考,具体内容如下
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<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: 60px;
width: 60px;
display: block;
z-index: 21;
cursor: pointer;
}
</style>
</head>
<body>
<img src="img/reward.png" class="journal-reward" />
<script src="jquery.min.js"></script>
<script src="flutter-hearts-zmt.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
flutter-hearts-zmt.js
! 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 = [
'img/1.png',
'img/2.png',
'img/3.png',
'img/4.png',
'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);
});
来源:https://blog.csdn.net/qq_36591333/article/details/79959687


猜你喜欢
- python变量1. 定义变量 (创建变量)变量就是一种用来保存数据的容器,使用变量就是使用变量中保存的数据语法:变量名 = 数据1.变量名
- 用下面方法解决(管理mysql用的是navicat).,设置以下几个参数的值后就正常了,以下语句也可以在mysql的控制台上执行 . sho
- 有时候我们需要在程序里执行一些cmd命令,使用os或者其它模块中的popen方法去执行这个问题一般是程序内有输入导致的,这个输入可以是inp
- 以titanic数据集为例。其中name列是字符串,现在想从其中提取title作为新的一列。例如:# create new Title co
- 经常使用python检测服务器是否能ping通, 程序是否正常运行(检测对应的端口是否正常)以前使用shell脚本的写法如下:PINGRET
- 107条javascript(js)常用的方法技巧,十分的实用,相信看了下面的这些js编程技巧和方法,能够给javascript初学者解决很
- 我就废话不多说了,大家还是直接看代码吧~lt=client.fangjia.district_stat_all_0416dl = dt.fi
- 目录redigo 对 发布订阅的使用订阅的主题发布redigo 对 发布订阅的使用redigo 对redis 的发布订阅机制放在pubsub
- python2中的unicode()函数在python3中会报错:NameError: name 'unicode' is
- 前两天简单认识了一下PyQt5,通过练习开发了一款在Window下自定义关机的小工具,代码如下:import os,sys,timefrom
- var str='1250' ; alert( Number(str) ); //得到1250 alert(parseInt
- jupyter notebook 自定义python解释器jupyter notebook 和虚拟环境的好处就不多废话了jupyter no
- 本文实例讲述了Python实现栈和队列的简单操作方法。分享给大家供大家参考,具体如下:先简单的了解一下数据结构里面的栈和堆:栈和队列是两种基
- 很多时候,我们需要实时的绘制曲线,如实时的绘制串口接收到的数据。最先想到的解决策略是类似于Matlab种的drawnow函数。在python
- 1、用户管理mysql的用户信息保存在了mysql.user中:select * from mysql.user\G************
- 如下所示:# x = ['c b a',"e d f"]# y = []# for i in x:# f
- 一、变量1.变量•指在程序执行过程中,可变的量;•定义一个变量,就会伴随有3个特征,分别是内存ID、数据类型和变量值。•其他语言运行完之前,
- Http定义了与 服务器的交互方法,其中除了一般我们用的最多的GET,POST 其实还有PUT和DELETE 根据RFC2616标
- 一、问题引发思考前阵子与同事探讨一个小需求时又遇到了按钮表示“动作”和表示“状态”间矛盾问题。想想这个问题多年前已经开始讨论了,所以在此整理
- 1 基本场景比如你有 N 个 cache 服务器(后面简称 cache ),那么如何将一个对象 object 映射到 N 个 cache 上