<!DOCTYPE html> <html> <head> <title>鼠标拖拽星星特效</title> <style> .shubiao { margin: 0; padding: 0; background-color: #000; cursor: pointer; } .star { position: absolute; width: 20px; height: 20px; background-color: #fff; border-radius: 50%; box-shadow: 0 0 10px #fff; opacity: 0; pointer-events: none; transform: translate(-50%, -50%); animation: fade-in 0.5s ease-out; } @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } } </style> </head> <body> <script> document.addEventListener('mousemove', function(event) { createStar(event.clientX, event.clientY); }); function createStar(x, y) { var star = document.createElement('div'); star.classList.add('star'); star.style.left = x + 'px'; star.style.top = y + 'px'; document.shubiao.appendChild(star); setTimeout(function() { star.remove(); }, 500); } </script> </body> </html>怎么改成css
时间: 2024-03-13 09:47:43 浏览: 95
HTML参考手册
这段代码已经包含了CSS样式,如果你想把CSS单独提取出来,可以将<style>标签里的样式代码复制到一个单独的CSS文件中,然后在HTML文件中使用<link>标签引入。具体步骤如下:
1. 复制以下CSS代码到一个单独的文件中,例如命名为style.css:
```
.shubiao {
margin: 0;
padding: 0;
background-color: #000;
cursor: pointer;
}
.star {
position: absolute;
width: 20px;
height: 20px;
background-color: #fff;
border-radius: 50%;
box-shadow: 0 0 10px #fff;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -50%);
animation: fade-in 0.5s ease-out;
}
@keyframes fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
```
2. 在HTML文件的<head>标签中,使用<link>标签引入该CSS文件:
```
<head>
<title>鼠标拖拽星星特效</title>
<link rel="stylesheet" href="style.css">
</head>
```
这样就可以将CSS样式与HTML代码分离,使代码更加清晰和易于维护。
阅读全文