写一段网页前端代码,要有很多很多雪花落下来
时间: 2023-02-23 09:36:23 浏览: 51
<script>
$(document).ready(function() {
// 设置变量
let flake = $("<div />").css({
"position": "absolute",
"top": "-50px"
}).html("❄");
// 每个雪花都有不同的样式
let generateFlake = function() {
let startPositionLeft = Math.random() * window.innerWidth;
let endPositionLeft = Math.random() * window.innerWidth;
let durationFall = window.innerHeight * 10 + Math.random() * 5000;
let sizeFlake = (Math.random()*3) + 2 + "px";
let delayFall = Math.random() * 5000;
let flakeClone = flake.clone().css({
"left": startPositionLeft,
"font-size": sizeFlake,
"color": "#FFF",
"opacity": "0.5"
});
flakeClone.appendTo($("body"));
flakeClone.delay(delayFall).animate({
top: window.innerHeight,
left: endPositionLeft,
opacity: 0.2
}, durationFall, function() {
$(this).remove()
});
};
// 设置循环
setInterval(generateFlake, 200);
})
</script>