let trails = [];
function createTrail(x, y) {
const trail = document.createElement('div');
trail.className = 'trail';
trail.style.left = `${x}px`;
trail.style.top = `${y}px`;
document.body.appendChild(trail);
// 使用setTimeout在200毫秒后移除拖尾
setTimeout(() => {
document.body.removeChild(trail);
trails = trails.filter(t => t !== trail); // 从数组中移除已删除的拖尾(如果需要的话)
}, 200);
// 如果需要,可以将拖尾添加到数组中以便后续处理(例如,清除所有拖尾)
// trails.push(trail);
}
document.addEventListener('mousemove', function(e) {
const rect = document.body.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
// 清除旧的拖尾(如果需要的话)
// trails.forEach(trail => {
// trail.remove();
// });
// trails = []; // 重置拖尾数组
// 创建新的拖尾
createTrail(x, y);
// 注意:这里为了简单起见,我们没有保留拖尾数组,而是直接创建和销毁拖尾
});
1123
123