jQuery-弹幕

本文介绍了一个简单的HTML页面,该页面使用JavaScript实现了基本的弹幕显示功能。用户可以在输入框中输入文字并通过按钮发送,文字将以滚动形式显示在指定区域。此外还提供了一个清空当前显示弹幕的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

该方法可能有bug,毕竟简单粗暴

<!DOCTYPE html>
<html>


<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-1.11.0.js"></script>
<style>
* {
margin: 0;
padding: 0;
}

.video {
margin: 50px auto 10px auto;
width: 500px;
height: 500px;
border: 1px solid pink;
}

.btn {
width: 40px;
height: 25px;
background: #26d4bd;
color: #fff;
border: none;
outline: none;
}
.active{
width: 65px;
background: red;
}
.box{
margin: 0px auto;
width: 500px;
height: 500px;
}
</style>
</head>


<body>
<div class="video" id="video"></div>
<div class="box">
<input type="text" id="text"/> <button type="button" id="btn" class="btn">发送</button>
<button type="button" id="clear" class="btn active">清空弹幕</button>
</div>

<script>
$("#btn").click(function(){
$("#video").append('<marquee behavior="scroll" direction="left" loop="1" scrollamount="100" scrolldelay="500">'+$("#text").val()+'</marquee>')
$("#text").val("")
})

$("#clear").click(function(){
$("#video").empty()
})
</script>
</body>


</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值