前端案例之视频弹幕

基础版本

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<style>
		* {
			margin: 0;
			padding: 0;
		}

		.dm {
			width: 800px;
			height: 600px;
			background-color: blue;
			margin: 0 auto;
		}

		.box {
			height: 500px;
			background-color: #000;
			position: relative;
			overflow: hidden;
		}

		video {
			width: 100%;
			height: 100%;
		}

		.info {
			text-align: center;
			margin-top: 20px;
		}

		input[type=text] {
			width: 500px;
			height: 50px;
		}

		input[type=button] {
			height: 50px;
			width: 100px;

		}

		span {
			position: absolute;
			/* 文本强制不换行 */
			white-space: nowrap;
			font: bold 18px '微软雅黑';
		}
	</style>

</head>

<body>
	<div class="dm">
		<div class="box">
			<video src="m.mp4" controls></video>
		</div>
		<div class="info">
			<input type="text" maxlength="30" id="txt">
			<input type="button" value="发射" id="emit">
		</div>
	</div>
	<script src="jquery-1.12.4.js"></script>
	<script>
		// 0. 用一个数组保存一组颜色值
		var colors = ['red', 'green', 'yellow', '#fff', 'pink', 'blue'];
		// 1. 给发射按钮注册点击事件
		$('#emit').click(function () {
			// 2. 获取文本框的内容
			var v = $('#txt').val();
			// 3. 创建span标签,并设置内容,设置样式,最后追加到类名为box的div中
			var $span = $('<span></span>');
			$span.text(v)
			.css({
					left: $('.box').width(),
					top: parseInt(Math.random() * $('.box').height()),
					color: colors[parseInt(Math.random() * colors.length)]
				}).appendTo('.box');
			// 4. 让当前的span产生动画 left 为-span的宽度
			$span.animate({
				left: -1 * $span.width()
			}, 6000, 'linear', function () {
				// 当动画结束后,删除该元素
				$span.remove();
			})
		});
	</script>

</body>

</html>

加强版本

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<style>
		* {
			margin: 0;
			padding: 0;
		}

		.dm {
			width: 800px;
			height: 600px;
			background-color: blue;
			margin: 0 auto;
		}

		.box {
			height: 500px;
			background-color: #000;
			position: relative;
			overflow: hidden;
		}

		video {
			width: 100%;
			height: 100%;
		}

		.info {
			text-align: center;
			margin-top: 20px;
		}

		input[type=text] {
			width: 500px;
			height: 50px;
		}

		input[type=button] {
			height: 50px;
			width: 100px;

		}

		span {
			position: absolute;
			/* 文本强制不换行 */
			white-space: nowrap;
			font: bold 18px '微软雅黑';
		}
	</style>

</head>

<body>
	<div class="dm">
		<div class="box">
 <!-- controls 如果出现该属性,则向用户显示控件,比如播放按钮。 -->
			<video src="m.mp4" controls></video>
		</div>
		<div class="info">
			<input type="radio" value="" id="ban" name="1">精简</input>
			<input type="radio" value="" id="vip" name="1">VIP尊享</input>
			<input type="text" maxlength="30" id="txt">
			<input type="button" value="发射" id="emit">
		</div>
	</div>
	<script src="jquery-1.12.4.js"></script>
	<script>
		// 0. 用一个数组保存一组颜色值
		var colors = ['red', 'green', 'yellow', '#fff', 'pink', 'blue'];

		//定义一个变量,定义其他样式的
		b = 0
		$('#ban').click(function () {
			b = 1;
		});
		$('#vip').click(function () {
			b = 2;
		});




		// 1. 给发射按钮注册点击事件
		$('#emit').click(function () {
			// 2. 获取文本框的内容
			var v = $('#txt').val();
			// 3. 创建span标签,并设置内容,设置样式,最后追加到类名为box的div中
			var $span = $('<span></span>');

			//定义CSS样式,让它是一个数组形式表现
			css = [{
					"left": $('.box').width(),
					"top": parseInt(Math.random() * $('.box').height()),
					"color": colors[parseInt(Math.random() * colors.length)]
				},
				{
					"left": $('.box').width(),
					"top": parseInt(Math.random() * ($('.box').height() / 2)),
					"color": colors[parseInt(Math.random() * colors.length)]
				},
				{
					"left": $('.box').width(),
					"top": parseInt(Math.random() * $('.box').height()),
					"color": "yellow",
					"fontSize": 50,
					"fontFamily": "楷体"
				}
			]
			//看看能不能打印出数组中的东西
			// console.log(abc[1])

			$span.text(v)
				.css(css[b])
				.appendTo('.box');

			// 4. 让当前的span产生动画 left 为-span的宽度

			//打印出文本长度
			// console.log(v.length)

			$span.animate({
					left: -1 * $span.width()
				}, (30 - v.length) * 333, 'linear',
				function () {
					// 当动画结束后,删除该元素
					$span.remove();
				})
		});
	</script>

</body>

</html>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于视频弹幕网站的开发,可以考虑以下技术选型: 1. 前端开发:可以选择使用 HTML、CSS 和 JavaScript 进行网页的开发,同时可以考虑使用一些前端框架,如React、Vue.js或Angular等来加速开发和提高用户界面的交互体验。 2. 后端开发:对于后端开发,可以选择使用一种服务器端编程语言,如Python、Node.js、Java或Ruby等。根据团队成员的技术背景和项目需求,选择合适的后端框架,如Django、Flask、Express.js或Ruby on Rails等。 3. 数据库:考虑到弹幕网站可能需要存储大量的弹幕数据和用户信息,可以选择关系型数据库(如MySQL、PostgreSQL)或非关系型数据库(如MongoDB)来存储数据。 4. 弹幕功能实现:可以使用WebSocket技术来实时传输和展示弹幕,也可以使用HTTP请求来发送和接收弹幕。对于弹幕的存储和管理,可以使用数据库进行存储,并结合前后端的交互来实现。 5. 视频处理:如果需要对视频进行处理,如视频上传、转码、截取等操作,可以考虑使用FFmpeg等流行的视频处理工具。 6. 服务器和部署:选择合适的云服务提供商(如AWS、阿里云、腾讯云等)来搭建服务器,并根据网站的流量和访问需求进行服务器的配置和部署。 综上所述,技术选型应根据项目需求、团队成员技术背景和预算等因素进行综合考虑,并选择适合的技术栈来开发视频弹幕网站。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值