1. 程式人生 > >HTML(實現滑鼠滑過留下痕跡的效果)

HTML(實現滑鼠滑過留下痕跡的效果)

首先我們先要把圖形打出來

<style>
        div{
            width: 10px;
            height: 10px;
            background: red;
            position: absolute;
            border-radius: 50%;
        }
    </style>

  然後寫出滑動滑鼠事件向那個方向移動

<script>
    document.onmousemove = function () {
        var div = document.createElement('div');
        var x = event.clientX;
        var y = event.clientY;
        div.style.left = x + "px";
        div.style.top = y + "px";
        document.body.appendChild(div);
    }
</script>