Files
ClassContent/历届学生/fontendseven/项目练习/个人练习/蔡敏/练习/js/function.html
2024-09-27 02:06:13 +08:00

62 lines
1.3 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>Document</title>
<style>
body,
html {
width: 100%;
height: 100%;
margin: 0;
}
span {
position: absolute;
transition: all 1s ease;
}
</style>
</head>
<body>
</body>
<script>
var text = ["富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法治", "爱国", "敬业", "诚信", "友善"];
var index = 0;
document.querySelector("body").onclick = function (event) {
var x = event.clientX, y = event.clientY
var span = document.createElement("span")
span.style.left = `${x}px`
span.style.top = `${y}px`
span.innerText = text[index]
span.style.color = `hsl(${Math.random() * 360},100%,50%)`
console.log(span);
index++
index > 11 ? index = 0 : ""
document.querySelector("body").appendChild(span)
setTimeout(function () {
span.style.top = `${y - 100}px`
},100)
setTimeout (()=> {
document.querySelector("body").removeChild(span)
},1100)
}
</script>
</html>