js+css实现下雪动画效果代码

代码语言:html

所属分类:动画

代码描述:js+css实现下雪动画效果代码

代码标签: js css 下雪 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
  
<style>
body {
  margin: 0;
  overflow: hidden;
  background-color: #0A0A0A;
  color: white;
  font-family: sans-serif;
}

.snowflake {
  position: absolute;
  top: -50px;
  color: white;
  user-select: none;
  animation: fall linear infinite;
}

@keyframes fall {
  to {
    transform: translateY(260px) rotate(360deg) translateX(20px);
    opacity: 0;
  }
}
</style>


  
</head>

<body translate="no">
  
  
      <script >
const snowflakeCount = 100;
let mouseX = window.innerWidth / 2;
let smoothingFactor = 0.05;
let targetMouseX = mouseX;

window.addEventListener('mousemove', event => {
  targetMouseX = event.clientX;
});

const smoothMouseUpdate = () => {
  mouseX += (targetMouseX - mouseX) * smoothingFactor;
  requestAnimationFrame(smoothMouseUpdate);
};

smoothMouseUpdate();

for (let i = 0; i < snowflakeCount; i++) {
  const snowflake = document.createElement('div.........完整代码请登录后点击上方下载按钮下载查看

网友评论0