


HTML5 programming practice part one - sample code sharing for implementing HTML5 clock
HTML5ProgrammingPractical Combat One-Implementation HTML5 clock sample code sharing
nbsp;html> <meta> <title>超酷HTML5时钟(作者:http://www.cnblogs.com/jscode/)</title> <style> .time { text-align: center; width:400px; font-family: "Book Antiqua",Palatino,serif; font-size: 40px; font-weight: bold; text-shadow: 1px 1px 3px #333; position:absolute; } .time em { background: white; position: absolute; top: 5px; left: 130px; height: 18px; width: 140px; opacity: 0.4; } </style> <script> var canvas, context; function DrawClock() { canvas = document.getElementById("canvas"); context = canvas.getContext("2d"); setInterval("drawbackground()", 1000); } function drawbackground() { var radius = Math.min(canvas.width / 2, canvas.height / 2) - 15; var centerx = canvas.width / 2; var centery = canvas.height / 2; context.clearRect(0, 0, canvas.width, canvas.height); context.save(); context.lineWidth = 15; context.fillStyle = "#EFEFEF"; context.strokeStyle = "#000"; context.beginPath(); context.arc(centerx, centery, radius, 0, Math.PI * 2, 0); context.fill(); context.stroke(); context.closePath(); context.restore(); for (var i = 0; i < 60; i++) { context.save(); context.fillStyle = "#EFEFEF"; context.strokeStyle = "#000"; if (i % 5 == 0) { context.lineWidth = 3; } context.beginPath(); context.moveTo(centerx, centery); context.lineTo(centerx + (radius-6) * Math.cos(i * 6 * Math.PI / 180), centery - (radius-5) * Math.sin(i * 6 * Math.PI / 180)); context.fill(); context.stroke(); context.closePath(); context.restore(); } context.moveTo(centerx, centery); context.save(); context.fillStyle = "#EFEFEF"; context.strokeStyle = "#EFEFEF"; context.beginPath(); context.arc(centerx, centery, radius-15, 0, Math.PI * 2, 0); context.fill(); context.stroke(); context.closePath(); context.restore(); var r = radius - 25; context.font = "bold 20px 宋体"; Drawtext("1", centerx + (Math.cos(60 * Math.PI / 180) * r), centery - (Math.sin(60 * Math.PI / 180) * r)); Drawtext("2", centerx + (Math.cos(30 * Math.PI / 180) * r), centery - (Math.sin(30 * Math.PI / 180) * r)); Drawtext("3", centerx + (Math.cos(0 * Math.PI / 180) * r), centery - (Math.sin(0 * Math.PI / 180) * r)); Drawtext("4", centerx + (Math.cos(330 * Math.PI / 180) * r), centery - (Math.sin(330 * Math.PI / 180) * r)); Drawtext("5", centerx + (Math.cos(300 * Math.PI / 180) * r), centery - (Math.sin(300 * Math.PI / 180) * r)); Drawtext("6", centerx + (Math.cos(270 * Math.PI / 180) * r), centery - (Math.sin(270 * Math.PI / 180) * r)); Drawtext("7", centerx + (Math.cos(240 * Math.PI / 180) * r), centery - (Math.sin(240 * Math.PI / 180) * r)); Drawtext("8", centerx + (Math.cos(210 * Math.PI / 180) * r), centery - (Math.sin(210 * Math.PI / 180) * r)); Drawtext("9", centerx + (Math.cos(180 * Math.PI / 180) * r), centery - (Math.sin(180 * Math.PI / 180) * r)); Drawtext("10", centerx + (Math.cos(150 * Math.PI / 180) * r), centery - (Math.sin(150 * Math.PI / 180) * r)); Drawtext("11", centerx + (Math.cos(120 * Math.PI / 180) * r), centery - (Math.sin(120 * Math.PI / 180) * r)); Drawtext("12", centerx + (Math.cos(90 * Math.PI / 180) * r), centery - (Math.sin(90 * Math.PI / 180) * r)); context.save(); context.fillStyle="black"; context.beginPath(); context.arc(centerx,centery,10,0,Math.PI*2,0); context.fill(); context.stroke(); context.closePath(); context.restore(); drawpoint(centerx, centery, radius); } function drawpoint(centerx, centery, radius) { var date = new Date(); var h = date.getHours(); h = h < 13 ? h : h - 12; var m = date.getMinutes(); var s = date.getSeconds(); var th = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(); var tm = m < 10 ? "0" + m : m; var ts = s < 10 ? "0" + s : s; document.getElementById("currtime").innerHTML = th + ":" + tm + ":" + ts; var hr = h * 30 * Math.PI / 180 + (m / 60) * 30 * Math.PI / 180 + 90 * Math.PI / 180; var mr = m * 6 * Math.PI / 180 + s / 60 * 6 * Math.PI / 180 + 90 * Math.PI / 180; var sr = s * 6 * Math.PI / 180 + 90 * Math.PI / 180; context.save(); context.lineWidth = 5; context.fillStyle = "darkgray"; context.strokeStyle = "black"; context.beginPath(); context.moveTo(centerx + 20 * Math.cos(hr), centery + 20 * Math.sin(hr)); context.lineTo(centerx - (radius - 120) * Math.cos(hr), centery - (radius - 120) * Math.sin(hr)); context.moveTo(centerx + 20 * Math.cos(mr), centery + 20 * Math.sin(mr)); context.lineTo(centerx - (radius - 80) * Math.cos(mr), centery - (radius - 80) * Math.sin(mr)); context.moveTo(centerx + 20 * Math.cos(sr), centery + 20 * Math.sin(sr)); context.lineTo(centerx - (radius - 50) * Math.cos(sr), centery - (radius - 50) * Math.sin(sr)); context.closePath(); context.fill(); context.stroke(); context.restore(); } function Drawtext(text, x, y) { context.save(); x -= (context.measureText(text).width / 2); y += 9; context.beginPath(); context.translate(x, y); context.fillText(text, 0, 0); context.restore(); } window.onload = DrawClock; </script> <h1 id="超酷HTML-时钟-作者-http-www-cnblogs-com-jscode">超酷HTML5时钟(作者:http://www.cnblogs.com/jscode/)</h1> <canvas> </canvas> <p><span>00:00:00</span> <em></em> </p>
Explanation of method function:
DrawClock method obtains Canvas context
drawbackground method is mainly to draw the background part of the clock: Borders, text, tick marks
drawpoint method is used to draw hour, minute, second lines
Drawtext method is used to add text
The above is the detailed content of HTML5 programming practice part one - sample code sharing for implementing HTML5 clock. For more information, please follow other related articles on the PHP Chinese website!

H5 is HTML5, the fifth version of HTML. HTML5 improves the expressiveness and interactivity of web pages, introduces new features such as semantic tags, multimedia support, offline storage and Canvas drawing, and promotes the development of Web technology.

Accessibility and compliance with network standards are essential to the website. 1) Accessibility ensures that all users have equal access to the website, 2) Network standards follow to improve accessibility and consistency of the website, 3) Accessibility requires the use of semantic HTML, keyboard navigation, color contrast and alternative text, 4) Following these principles is not only a moral and legal requirement, but also amplifying user base.

The H5 tag in HTML is a fifth-level title that is used to tag smaller titles or sub-titles. 1) The H5 tag helps refine content hierarchy and improve readability and SEO. 2) Combined with CSS, you can customize the style to enhance the visual effect. 3) Use H5 tags reasonably to avoid abuse and ensure the logical content structure.

The methods of building a website in HTML5 include: 1. Use semantic tags to define the web page structure, such as, , etc.; 2. Embed multimedia content, use and tags; 3. Apply advanced functions such as form verification and local storage. Through these steps, you can create a modern web page with clear structure and rich features.

A reasonable H5 code structure allows the page to stand out among a lot of content. 1) Use semantic labels such as, etc. to organize content to make the structure clear. 2) Control the rendering effect of pages on different devices through CSS layout such as Flexbox or Grid. 3) Implement responsive design to ensure that the page adapts to different screen sizes.

The main differences between HTML5 (H5) and older versions of HTML include: 1) H5 introduces semantic tags, 2) supports multimedia content, and 3) provides offline storage functions. H5 enhances the functionality and expressiveness of web pages through new tags and APIs, such as and tags, improving user experience and SEO effects, but need to pay attention to compatibility issues.

The difference between H5 and HTML5 is: 1) HTML5 is a web page standard that defines structure and content; 2) H5 is a mobile web application based on HTML5, suitable for rapid development and marketing.

The core features of HTML5 include semantic tags, multimedia support, form enhancement, offline storage and local storage. 1. Semantic tags such as, improve code readability and SEO effect. 2. Multimedia support simplifies the process of embedding media content through and tags. 3. Form Enhancement introduces new input types and verification properties, simplifying form development. 4. Offline storage and local storage improve web page performance and user experience through ApplicationCache and localStorage.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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),
