html+css+js完成代码弹出功能
html+css+js完成代码弹出功能
html+css+js完成代码弹出功能简介:本文讲解如何使用html+css+js实现代码在网页中弹射出来的功能。效果展示代码会不断的在屏幕上弹出然后消失
完整代码下面是完整的代码和详细的解释。代码语言:javascript代码运行次数:0运行复制<!DOCTYPE html>
<html>
<head>
<ti
html+css+js完成代码弹出功能
简介:本文讲解如何使用html+css+js实现代码在网页中弹射出来的功能。
效果展示
代码会不断的在屏幕上弹出然后消失
完整代码
下面是完整的代码和详细的解释。
代码语言:javascript代码运行次数:0运行复制<!DOCTYPE html>
<html>
<head>
<title>Code Effect</title>
<style>
/* 设置#code元素的样式 */
#code {
position: fixed; /* 元素固定在视口中 */
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: transparent; /* 背景透明 */
overflow: hidden; /* 溢出隐藏 */
color: rgb(0, 6, 150); /* 字体颜 */
font-size: 110px; /* 字体大小 */
font-family: 'Courier ew', monospace; /* 字体类型 */
}
</style>
</head>
<body>
<div id="code"></div>
<script>
/* 生成随机字符串并返回 */
function getRandomString() {
ct stringList = [
"#include<iostream>\nusing namespace std;\n\nint main()\n{\n\tcout << \"Hello, World!\" << endl;\n\treturn 0;\n}",
"import math\n\nprint(math.sqrt(2))",
"for i in range(10):\n print(i)",
"public class HelloWorld {\n public static void main(String[] args) {\n println(\"Hello, World!\");\n }\n}",
"cole.log(\"Hello, World!\");",
"def hello():\n print(\"Hello, World!\")\nhello()",
"var s = \"Hello, World!\";\ncole.log(s);",
"using System;\n\nclass Program\n{\n static void Main(string[] args)\n {\n Cole.WriteLine(\"Hello, World!\");\n }\n}"
];
return stringList[Math.floor(Math.random() * stringList.length)];
}
/* 创建代码块元素 */
function createCodeElement() {
ct element = ("pre"); /* 用<pre>标签创建元素 */
element.innerHTML = getRandomString(); /* 将随机字符串作为元素内容 */
element.style.position = "absolute"; /* 元素的定位方式设为绝对定位 */
element. = Math.random() * 100 + "%"; /* 随机设置元素的上边距 */
element.style.left = Math.random() * 100 + "%"; /* 随机设置元素的左边距 */
element. = "translate(-50%, -50%)"; /* 将元素居中显示 */
element.style.animation = "floatup 10s ease-out forwards"; /* 设置元素的动画效果 */
document.getElementById("code").appendChild(element); /* 将元素添加到#code中 */
setTimeout(() => {
element.remove(); /* 在5秒后删除元素 */
}, 5000);
}
setInterval(createCodeElement, 200); /* 每隔200毫秒调用createCodeElement函数来添加代码块 */
</script>
</body>
</html>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:202-04-24,如有侵权请联系 cloudcommunity@tencent 删除ctmlelement函数字符串 #感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
上传时间: 2025-07-19 10:42:06
推荐阅读
留言与评论(共有 15 条评论) |
本站网友 teamviewer许可证 | 1分钟前 发表 |
fixed; /* 元素固定在视口中 */ top | |
本站网友 加入wto | 29分钟前 发表 |
'Courier ew' | |
本站网友 spiders | 4分钟前 发表 |
rgb(0 | |
本站网友 武汉商场 | 14分钟前 发表 |
代码语言:javascript代码运行次数:0运行复制<!DOCTYPE html> <html> <head> <title>Code Effect</title> <style> /* 设置#code元素的样式 */ #code { position | |
本站网友 雯雅婷桌面玩偶 | 21分钟前 发表 |
代码语言:javascript代码运行次数:0运行复制<!DOCTYPE html> <html> <head> <title>Code Effect</title> <style> /* 设置#code元素的样式 */ #code { position | |
本站网友 菲律宾简介 | 28分钟前 发表 |
"for i in range(10) | |
本站网友 博客大全 | 8分钟前 发表 |
transparent; /* 背景透明 */ overflow | |
本站网友 贫血的原因 | 12分钟前 发表 |
"public class HelloWorld {\n public static void main(String[] args) {\n println(\"Hello | |
本站网友 细菌性阴炎 | 10分钟前 发表 |
如有侵权请联系 cloudcommunity@tencent 删除前往查看ctmlelement函数字符串 | |
本站网友 小头症 | 17分钟前 发表 |
World!\")\nhello()" | |
本站网友 西苑阳光翠庭 | 15分钟前 发表 |
World!\")\nhello()" | |
本站网友 怀孕31周 | 25分钟前 发表 |
100%; height | |
本站网友 深圳盐田二手房 | 25分钟前 发表 |
代码语言:javascript代码运行次数:0运行复制<!DOCTYPE html> <html> <head> <title>Code Effect</title> <style> /* 设置#code元素的样式 */ #code { position | |
本站网友 kb974431 | 3分钟前 发表 |
"var s = \"Hello |