当前位置:网站首页>Cavans realizes Static Rolling barrage
Cavans realizes Static Rolling barrage
2022-07-26 13:41:00 【Tangce】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- Bullet screen text -->
<div class="video-x"></div>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
// bullet chat
var dataBarrage = [{
value: " Static dead data is used ",
color: "blue",
range: [0, 0.5]
},
{
value: " Random loop playback ",
color: "blue",
range: [0, 0.6]
},
{
value: " It can control the area and vertical distribution range ",
color: "blue",
range: [0, 0.5]
},
{
value: " The font size and speed are set in the method ",
color: "black",
range: [0.1, 1]
},
{
value: " Suitable for some static pages ",
color: "black",
range: [0.2, 1]
},
{
value: " be based on canvas Realization ",
color: "black",
range: [0.2, 0.9]
},
{
value: " therefore IE9+ Browser only ",
color: "black",
range: [0.2, 1]
},
{
value: " You can set the border color ",
color: "black",
range: [0.2, 1]
},
{
value: " The default text color is white ",
color: "black",
range: [0.2, 0.9]
},
{
value: " If the text color does not want white ",
color: "black",
range: [0.2, 1]
},
{
value: " You need to adjust yourself JS",
color: "black",
range: [0.6, 0.7]
},
{
value: " If you need a real and video interactive barrage ",
color: "black",
range: [0.2, 1]
},
{
value: " You can go back to the original ",
color: "black",
range: [0, 0.9]
},
{
value: " Look at another demo",
color: "black",
range: [0.7, 1]
},
{
value: " Here is the space occupying barrage ",
color: "black",
range: [0.7, 0.95]
},
{
value: " High energy warning ahead !!!",
color: "orange",
range: [0.5, 0.8]
},
{
value: " High energy warning ahead !!!",
color: "orange",
range: [0.5, 0.9]
},
{
value: " High energy warning ahead !!!",
color: "orange",
range: [0, 1]
},
{
value: " High energy warning ahead !!!",
color: "orange",
range: [0, 1]
}
];
// Barrage method
var canvasBarrage = function (canvas, data) {
if (!canvas || !data || !data.length) {
return;
}
if (typeof canvas == "string") {
canvas = document.querySelector(canvas);
canvasBarrage(canvas, data);
return;
}
var context = canvas.getContext("2d");
// canvas.width = '';
// canvas.height = '';
// Storage instance
var store = {};
// Size
var fontSize = 12;
// Example method
var Barrage = function (obj, index) {
// Random x Coordinates are abscissa , about y Ordinate , And the amount of change moveX
this.x = (1 + (index * 0.1) / Math.random()) * canvas.width;
this.y =
obj.range[0] * canvas.height +
(obj.range[1] - obj.range[0]) * canvas.height * Math.random() +
36;
if (this.y < fontSize) {
this.y = fontSize;
} else if (this.y > canvas.height - fontSize) {
this.y = canvas.height - fontSize;
}
this.moveX = 1 + Math.random() * 3;
this.opacity = 0.8 + 0.2 * Math.random();
this.params = obj;
this.draw = function () {
var params = this.params;
// According to this time x Position draw text
context.strokeStyle = params.color;
context.font =
"bold " + fontSize + 'px "microsoft yahei", sans-serif';
context.fillStyle = "rgba(255,255,255," + this.opacity + ")";
context.fillText(params.value, this.x, this.y);
context.strokeText(params.value, this.x, this.y);
};
};
data.forEach(function (obj, index) {
store[index] = new Barrage(obj, index);
});
// Draw barrage text
var draw = function () {
for (var index in store) {
var barrage = store[index];
// Position change
barrage.x -= barrage.moveX;
if (barrage.x < -1 * canvas.width * 1.5) {
// When moving to the outside of the canvas, continue to move from the left
barrage.x = (1 + (index * 0.1) / Math.random()) * canvas.width;
barrage.y =
(barrage.params.range[0] +
(barrage.params.range[1] - barrage.params.range[0]) *
Math.random()) *
canvas.height;
if (barrage.y < fontSize) {
barrage.y = fontSize;
} else if (barrage.y > canvas.height - fontSize) {
barrage.y = canvas.height - fontSize;
}
barrage.moveX = 1 + Math.random() * 3;
}
// Draw a circle according to the new position
store[index].draw();
}
};
// Canvas rendering
var render = function () {
// Clear the canvas
context.clearRect(0, 0, canvas.width, canvas.height);
// Draw all the circles on the canvas
draw();
// Continue rendering
requestAnimationFrame(render);
};
render();
};
var canvas = '<canvas id="canvasBarrage" class="canvas-barrage"></canvas>'
$('.video-x').html(canvas);
canvasBarrage("#canvasBarrage", dataBarrage);
})
</script>
</body>
</html>
边栏推荐
- panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)
- Target detection network r-cnn series
- Dimension disaster dimension disaster suspense
- El table implements editable table
- 421. 数组中两个数的最大异或值
- 【Oauth2】七、微信OAuth2授权登录
- B+ tree selection index (2) -- MySQL from entry to proficiency (23)
- [collection of topics that C language learners must know 1] consolidate the foundation and steadily improve
- One stroke problem (Chinese postman problem)
- Tianjin emergency response Bureau and central enterprises in Tianjin signed an agreement to deepen the construction of emergency linkage mechanism
猜你喜欢

Oom caused by improper use of multithreading

Solve the problem that the remote host cannot connect to the MySQL database

详解关系抽取模型 CasRel

官宣!艾德韦宣集团与百度希壤达成深度共创合作

Activity.onStop() 延迟10秒?精彩绝伦的排查历程

The last time I heard about eBay, or the last time

Why does WPS refuse advertising?

力扣------字符串中的单词数

Seven steps to copywriting script ---- document team collaborative management

Ros2 learning (1) introduction to ros2
随机推荐
Time complexity and space complexity
Sword finger offer (VII): Fibonacci sequence
【C语言学习者必会的题目集锦1】巩固基础,稳步提高
数据泄漏、删除事件频发,企业应如何构建安全防线?
Leetcode 1523. count odd numbers within the interval
HCIP第十二天笔记整理(BGP联邦、选路规则)
panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)
HCIP第十一天比较(BGP的配置、发布)
Basic sentence structure of English ----- origin
终极套娃 2.0 | 云原生交付的封装
Comparator (interface between comparable and comparator)
.net6与英雄联盟邂逅之——根据官方LCU API制作游戏助手
Dimension disaster dimension disaster suspense
8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
JSON数据传递参数&日期型参数传递
向路由组件传递参数
Solution 5g technology helps build smart Parks
Feixin, which lasted 15 years and had 500million users, was completely dead
This article explains the FS file module and path module in nodejs in detail
Pytoch learning notes (I) installation and use of common functions