这次给大家带来js实现简易24小时时钟,js实现简易24小时时钟的注意事项有哪些,下面就是实战案例,一起来看一下。
js代码
var canvas = document.getElementById("clock"); var clock = canvas.getContext("2d"); function zhong() { clock.save(); //开始画外层圆 clock.translate(200, 200); clock.strokeStyle = 'black'; clock.lineWidth = 3; clock.beginPath(); clock.arc(0, 0, 195, 0, 2 * Math.PI); clock.stroke(); //时钟上的数字 var shuzi = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2]; clock.font = "30px Arial"; clock.textAlign = "center"; clock.textBaseline = "middle"; shuzi.forEach(function(number, i) { var rad = 2 * Math.PI / 12 * i; var x = Math.cos(rad) * 180; var y = Math.sin(rad) * 180; clock.fillText(number, x, y); }); // 小圆点 for(j = 0; j <p>相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!</p><p>推荐阅读:</p><!--content end-->
以上就是js实现简易24小时时钟的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号