代码如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>HTML CLOCK</title> </head> <body> <canvas width="500" height="500" id="clock"> 你的浏览器不支持canvas标签,时针显示不出来哦! </canvas> <script type="text/javascript"> //画布背景颜色 var clockBackGroundColor = "#ABCDEF"; //时针颜色 var hourPointColor = "#000"; //时针粗细 var hourPointWidth = 7; //时针长度 var hourPointLength = 100; //分针颜色 var minPointColor = "#000"; //分针粗细 var minPointWidth = 5; //分针长度 var minPointLength = 150; //秒针颜色 var secPointColor = "#F00"; //秒针粗细 var secPointWidth = 3; //秒针长度 var secPointLength = 170; //表盘颜色 var clockPanelColor = "#ABCDEF"; //表盘刻度颜色 var scaleColor = "#000"; //表盘大刻度宽度 3 6 9 12 var scaleBigWidth = 9; //表盘大刻度的长度 var scaleBigLength = 15; //表盘小刻度的宽度 var scaleSmallWidth = 5; //表盘小刻度的长度 var scaleSmallLength = 10; //圆心颜色 var centerColor = 'red'; //时钟画布 var clock = document.getElementById('clock'); clock.style.background = clockBackGroundColor; //时针画布的作图环境(画板) var panel = clock.getContext('2d'); //画线 /** *画线段 * * */ function drowLine(p,width,color,startX,startY,endX,endY,ran,cX,cY){ //保存传入的画板,相当于每次作画新开一个图层 p.save(); //设置画笔宽度 p.lineWidth = width; //设置画笔颜色 p.strokeStyle = color; //新开启作图路径,避免和之前画板上的内容产生干扰 p.beginPath(); p.translate(cX,cY); //旋转 p.rotate(ran); //移动画笔到开始位置 p.moveTo(startX,startY); //移动画笔到结束位置 p.lineTo(endX,endY); //画线操作 p.stroke(); //关闭作图路径,避免和之后在画板上绘制的内容产生干扰 p.closePath(); //在传入的画板对象上覆盖图层 p.restore(); } /** *画水平线 */ function drowHorizontalLine(p,width,length,color,startX,startY,ran,cX,cY){ drowLine(p,width,color,startX,startY,startX+length,startY,ran,cX,cY); } /** *画圈圈 */ function drowCircle(p,width,color,centreX,centreY,r){ p.save(); //设置画笔宽度 p.lineWidth = width; //设置画笔颜色 p.strokeStyle = color; //新开启作图路径,避免和之前画板上的内容产生干扰 p.beginPath(); //画圈圈 p.arc(centreX,centreY,r,0,360,false); //画线操作 p.stroke(); //关闭作图路径,避免和之后在画板上绘制的内容产生干扰 p.closePath(); //在传入的画板对象上覆盖图层 p.restore(); } function drowPoint(p,width,color,centreX,centreY,r){ p.save(); //设置画笔宽度 p.lineWidth = width; //设置画笔颜色 p.fillStyle = color; //新开启作图路径,避免和之前画板上的内容产生干扰 p.beginPath(); //画圈圈 p.arc(centreX,centreY,r,0,360,false); //画线操作 p.fill(); //关闭作图路径,避免和之后在画板上绘制的内容产生干扰 p.closePath(); //在传入的画板对象上覆盖图层 p.restore(); } function drowScales(p){ //画小刻度 for(var i = 0;i < 60;i++){ drowHorizontalLine(p,scaleSmallWidth,scaleSmallLength,scaleColor,195-scaleSmallLength,0,i*6*Math.PI/180,250,250); } //画大刻度 for(var i = 0;i < 12;i++){ drowHorizontalLine(p,i%3==0?scaleBigWidth*1.2:scaleBigWidth,i%3==0?scaleBigLength*1.2:scaleBigLength,scaleColor,195-scaleBigLength,0,i*30*Math.PI/180,250,250); //可以添加数字刻度 } } function drowHourPoint(p,hour){ drowHorizontalLine(p,hourPointWidth,hourPointLength,hourPointColor,-10,0,(hour-3)*30*Math.PI/180,250,250); } function drowMinPoint(p,min){ drowHorizontalLine(p,minPointWidth,minPointLength,minPointColor,-15,0,(min-15)*6*Math.PI/180,250,250); } function drowSecPoint(p,sec){ drowHorizontalLine(p,secPointWidth,secPointLength,secPointColor,-15,0,(sec-15)*6*Math.PI/180,250,250); } function drowClock(){ panel.clearRect(0,0,500,500); panel.fillText("",10,20); panel.fillText("<a href="http://www.jb51.net",10,40">http://www.jb51.net",10,40</a>); var date = new Date(); var sec = date.getSeconds(); var min = date.getMinutes(); var hour = date.getHours() + min/60; drowCircle(panel,7,'blue',250,250,200); drowScales(panel); drowHourPoint(panel,hour); drowMinPoint(panel,min); drowSecPoint(panel,sec); drowPoint(panel,1,centerColor,250,250,7); //drowHorizontalLine(panel,10,10,'red',-5,0,0,250,250); } //drowHorizontalLine(panel,7,30,'#F00',0,0,Math.PI,250,250); drowClock(); setInterval(drowClock,1000); function save(){ var image = clock.toDataURL("image/png").replace("image/png", "image/octet-stream"); location.href=image; } </script> </body> </html>
【相关推荐】
1. HTML5开发手机应用-详细介绍viewport的作用(图文)
3. HTML5 程序设计

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

The tools and frameworks that need to be mastered in H5 development include Vue.js, React and Webpack. 1.Vue.js is suitable for building user interfaces and supports component development. 2.React optimizes page rendering through virtual DOM, suitable for complex applications. 3.Webpack is used for module packaging and optimize resource loading.

HTML5hassignificantlytransformedwebdevelopmentbyintroducingsemanticelements,enhancingmultimediasupport,andimprovingperformance.1)ItmadewebsitesmoreaccessibleandSEO-friendlywithsemanticelementslike,,and.2)HTML5introducednativeandtags,eliminatingthenee

H5 improves web page accessibility and SEO effects through semantic elements and ARIA attributes. 1. Use, etc. to organize the content structure and improve SEO. 2. ARIA attributes such as aria-label enhance accessibility, and assistive technology users can use web pages smoothly.

"h5" and "HTML5" are the same in most cases, but they may have different meanings in certain specific scenarios. 1. "HTML5" is a W3C-defined standard that contains new tags and APIs. 2. "h5" is usually the abbreviation of HTML5, but in mobile development, it may refer to a framework based on HTML5. Understanding these differences helps to use these terms accurately in your project.

H5, or HTML5, is the fifth version of HTML. It provides developers with a stronger tool set, making it easier to create complex web applications. The core functions of H5 include: 1) elements that allow drawing graphics and animations on web pages; 2) semantic tags such as, etc. to make the web page structure clear and conducive to SEO optimization; 3) new APIs such as GeolocationAPI support location-based services; 4) Cross-browser compatibility needs to be ensured through compatibility testing and Polyfill library.

How to create an H5 link? Determine the link target: Get the URL of the H5 page or application. Create HTML anchors: Use the <a> tag to create an anchor and specify the link target URL. Set link properties (optional): Set target, title, and onclick properties as needed. Add to webpage: Add HTML anchor code to the webpage where you want the link to appear.

Solutions to H5 compatibility issues include: using responsive design that allows web pages to adjust layouts according to screen size. Use cross-browser testing tools to test compatibility before release. Use Polyfill to provide support for new APIs for older browsers. Follow web standards and use effective code and best practices. Use CSS preprocessors to simplify CSS code and improve readability. Optimize images, reduce web page size and speed up loading. Enable HTTPS to ensure the security of the website.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.