Files
ClassContent/历届学生/front-end-team-10/项目练习/学生项目/冯凯/练习/js练习/富强.html
2024-09-27 02:06:13 +08:00

78 lines
1.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>富强</title>
<style>
* {
margin: 0;
padding: 0;
}
span {
user-select: none;
position: fixed;
transition: all 1s;
}
body {
height: 100vh;
}
</style>
</head>
<body>
</body>
<script>
var textArr = ["富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法治", "爱国", "敬业", "诚信", "友善"];
var i = 0;
$("body").onclick = (e) => {
var { x, y } = e;//解构赋值
var span = document.createElement("span");
span.innerText = textArr[i];
span.style = `
color: hsla(${parseInt(Math.random() * 360)},100%,50%,1);
position: fixed;
left: ${x}px;
top: ${y}px;
`
$("body").appendChild(span) //添加span
//越界处理,数组的下标超过了 数组下标让他重新来
i++
if (i > 11) {
i = 0
}
sport(span,y)
}
function sport(span,y) {
setTimeout(() => {
span.style.top = `${y - 200}px`
}, 200)
setTimeout(() => {
$("body").removeChild(span)//延迟 1250毫秒过后删除
}, 1250)
}
function $(className) {
return document.querySelector(className)
}
function _(className) {
return document.querySelectorAll(className)
}
</script>
</html>