Html 5 小驚喜

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <canvas id="canvas" width="400" height="400" style="display:block; margin:0 auto; border:1px solid #ccc;"></canvas>
    <script>
        var canvas=document.getElementById('canvas');
        var context=canvas.getContext('2d');
        var width=canvas.width;
        var height=canvas.height;
        window.οnlοad= function () {
            context.fillStyle="black";
            context.fillRect(0,0,width,height);
            canvas.addEventListener("mousemove",draw);
            canvas.addEventListener("mouseout",hide)

        };
        function draw(event){
            var x=event.clientX-canvas.getBoundingClientRect().left;
            var y=event.clientY-canvas.getBoundingClientRect().top;
            context.clearRect(0,0,width,height);

            context.fillStyle="black";
            context.fillRect(0,0,width,height);

            context.save();
            context.beginPath();
            context.arc(x,y,100,0,2*Math.PI);
            context.fillStyle="white";
            context.fill();
            context.clip();

            context.font="bold 40px Arial";
            context.fillStyle="#058";
            context.textAlign="center";
            context.textBaseLine="middle";
            context.fillText("我們永遠在一起",width/2,height/2);
            context.restore();
        }
        function hide(){
            context.clearRect(0,0,width,height);
            context.fillStyle="black";
            context.fillRect(0,0,width,height);
        }
    </script>
</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章