一个酷炫的HTML页面的代码,一个基于HTML5 Canvas实现的预加载动画效果

```

<!DOCTYPE html>
<html>
<head>
    <title>Cool HTML5 Canvas Preloader</title>
    <style type="text/css">
        body {
            background-color: #222;
            color: #fff;
            font-family: Arial, sans-serif;
            font-size: 16px;
            line-height: 1.5;
            margin: 0;
            padding: 0;
            text-align: center;
        }
        canvas {
            display: block;
            margin: 0 auto;
            padding: 0;
        }
    </style>
</head>
<body>
    <canvas id="canvas"></canvas>
    <script type="text/javascript">
        var canvas = document.getElementById('canvas');
        var ctx = canvas.getContext('2d');
        var cw = canvas.width = 200;
        var ch = canvas.height = 200;
        var cx = cw / 2,
            cy = ch / 2;
        var rad = Math.PI / 180;
        var frames = 0;

        function drawCircle() {
            ctx.beginPath();
            ctx.strokeStyle = '#fff';
            ctx.lineWidth = 10;
            ctx.arc(cx, cy, 60, -90 * rad, (frames * 6 - 90) * rad);
            ctx.stroke();
        }

        function render() {
            frames++;
            ctx.clearRect(0, 0, cw, ch);
            drawCircle();
            requestAnimationFrame(render);
        }

        render();
    </script>
</body>
</html>

 

```

 

  • 25
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
下面是一个基于 HTML5 Canvas 的日期时间控件/日期选择器的示例代码,你可以根据自己的需求进行修改和优化: ```html <!DOCTYPE html> <html> <head> <title>Date Time Picker using HTML5 Canvas</title> <style type="text/css"> canvas { border: 1px solid #ccc; } </style> </head> <body> <canvas id="canvas" width="300" height="300"></canvas> <script type="text/javascript"> var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); function drawClock() { var now = new Date(); var sec = now.getSeconds(); var min = now.getMinutes(); var hr = now.getHours(); // Draw clock face ctx.beginPath(); ctx.arc(canvas.width/2, canvas.height/2, 100, 0, 2*Math.PI); ctx.fillStyle = '#fff'; ctx.fill(); ctx.lineWidth = 10; ctx.strokeStyle = '#333'; ctx.stroke(); // Draw hour marks ctx.lineWidth = 5; for (var i = 0; i < 12; i++) { var angle = (i - 3) * (Math.PI * 2) / 12; ctx.beginPath(); var x1 = canvas.width/2 + Math.cos(angle) * 80; var y1 = canvas.height/2 + Math.sin(angle) * 80; var x2 = canvas.width/2 + Math.cos(angle) * 70; var y2 = canvas.height/2 + Math.sin(angle) * 70; ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke(); } // Draw minute marks ctx.lineWidth = 2; for (var i = 0; i < 60; i++) { var angle = (i - 3) * (Math.PI * 2) / 60; ctx.beginPath(); var x1 = canvas.width/2 + Math.cos(angle) * 80; var y1 = canvas.height/2 + Math.sin(angle) * 80; var x2 = canvas.width/2 + Math.cos(angle) * 75; var y2 = canvas.height/2 + Math.sin(angle) * 75; ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke(); } // Draw hour hand ctx.lineWidth = 14; var angle = (hr - 3) * (Math.PI * 2) / 12; ctx.beginPath(); ctx.moveTo(canvas.width/2, canvas.height/2); ctx.lineTo(canvas.width/2 + Math.cos(angle) * 50, canvas.height/2 + Math.sin(angle) * 50); ctx.stroke(); // Draw minute hand ctx.lineWidth = 10; var angle = (min - 15) * (Math.PI * 2) / 60; ctx.beginPath(); ctx.moveTo(canvas.width/2, canvas.height/2); ctx.lineTo(canvas.width/2 + Math.cos(angle) * 70, canvas.height/2 + Math.sin(angle) * 70); ctx.stroke(); // Draw second hand ctx.lineWidth = 6; var angle = (sec - 15) * (Math.PI * 2) / 60; ctx.beginPath(); ctx.moveTo(canvas.width/2, canvas.height/2); ctx.lineTo(canvas.width/2 + Math.cos(angle) * 90, canvas.height/2 + Math.sin(angle) * 90); ctx.stroke(); // Draw center ctx.beginPath(); ctx.arc(canvas.width/2, canvas.height/2, 5, 0, 2*Math.PI); ctx.fillStyle = '#333'; ctx.fill(); } setInterval(drawClock, 1000); </script> </body> </html> ``` 这个示例代码中使用 canvas 绘制了一个时钟,你可以根据需要将它转换为日期时间控件/日期选择器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YCY^v^

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值