网页端实现鼠标拖尾
    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);  
  
        // 注意:这里为了简单起见,我们没有保留拖尾数组,而是直接创建和销毁拖尾  
    });  

评论

  1. daaa
    8 月前
    2024-7-23 15:14:45

    1123

  2. daaa
    8 月前
    2024-7-23 15:15:25

    123

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
下一篇