By (user deleted)
Description
It same time on your phone :)
Code
Insert this code into your page
[[html]]
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="400" height="400"
style="background-color:#333">
</canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var radius = canvas.height / 2;
ctx.translate(radius, radius);
radius = radius * 0.90
setInterval(drawClock, 1000);
function drawClock() {
drawFace(ctx, radius);
drawNumbers(ctx, radius);
drawTime(ctx, radius);
}
function drawFace(ctx, radius) {
var grad;
ctx.beginPath();
ctx.arc(0, 0, radius, 0, 2*Math.PI);
ctx.fillStyle = 'white';
ctx.fill();
grad = ctx.createRadialGradient(0,0,radius*0.95, 0,0,radius*1.05);
grad.addColorStop(0, '#333');
grad.addColorStop(0.5, 'white');
grad.addColorStop(1, '#333');
ctx.strokeStyle = grad;
ctx.lineWidth = radius*0.1;
ctx.stroke();
ctx.beginPath();
ctx.arc(0, 0, radius*0.1, 0, 2*Math.PI);
ctx.fillStyle = '#333';
ctx.fill();
}
function drawNumbers(ctx, radius) {
var ang;
var num;
ctx.font = radius*0.15 + "px arial";
ctx.textBaseline="middle";
ctx.textAlign="center";
for(num = 1; num < 13; num++){
ang = num * Math.PI / 6;
ctx.rotate(ang);
ctx.translate(0, -radius*0.85);
ctx.rotate(-ang);
ctx.fillText(num.toString(), 0, 0);
ctx.rotate(ang);
ctx.translate(0, radius*0.85);
ctx.rotate(-ang);
}
}
function drawTime(ctx, radius){
var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
//hour
hour=hour%12;
hour=(hour*Math.PI/6)+
(minute*Math.PI/(6*60))+
(second*Math.PI/(360*60));
drawHand(ctx, hour, radius*0.5, radius*0.07);
//minute
minute=(minute*Math.PI/30)+(second*Math.PI/(30*60));
drawHand(ctx, minute, radius*0.8, radius*0.07);
// second
second=(second*Math.PI/30);
drawHand(ctx, second, radius*0.9, radius*0.02);
}
function drawHand(ctx, pos, length, width) {
ctx.beginPath();
ctx.lineWidth = width;
ctx.lineCap = "round";
ctx.moveTo(0,0);
ctx.rotate(pos);
ctx.lineTo(0, -length);
ctx.stroke();
ctx.rotate(-pos);
}
</script>
</body>
</html>
[[/html]]
In action
After inserting
Thanks to tsangk for this great snippet: conditional-blocks
text above inserted with:
[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]
Other snippets posted by (user deleted)
Better Sidebar/更好的侧边栏 - 12 Nov 2024 01:36
Custom Identity Groups/自定义身份组 - 09 Nov 2024 18:49
Virtualization:VMclients - 08 Sep 2024 21:13
Applications:Wireshark - 08 Sep 2024 17:01
Applications:Nmap - 08 Sep 2024 16:06
diatomf - 15 Aug 2024 17:30
WORKING SEARCH for open and closed Wikidot sites - 13 Aug 2024 04:22
Kashmir tour packages - 10 Aug 2024 10:07
Where is Viscious? - 27 Jul 2024 17:30
snippets.lol - 24 Jul 2024 19:39
Level C-1018 - 18 Jun 2024 15:05
练习的草稿文本(1145141919810) - 07 Mar 2024 13:12
new cornify - 02 Feb 2024 07:26
To add tabs to your sandbox so you can have multiple drafts, use the following code: tabview tab Title 1 Text goes here - 30 Sep 2023 01:03
Text changes colors - 04 Jun 2023 09:49
Falling Snowflakes Effect - 15 Mar 2023 19:11
Column Layouts with CSS Grid - 01 Mar 2023 17:17
测试页面SCP - 17 Jan 2023 18:51
Do not try in life 2 - 14 Sep 2022 05:51
Do not try in life - 14 Sep 2022 05:50
Include Without iframe - 25 May 2022 03:40
Table Of Contents - 15 Apr 2022 22:52
How to use a Tag - 15 Apr 2022 07:44
Links - 15 Apr 2022 02:08
Headings - 14 Apr 2022 22:46
Show Username - 16 Feb 2022 04:40
Click Counter - 11 Nov 2021 16:25
8 Awesome Things That Will Make Your Website Awesome! - 02 Aug 2021 22:05
Thumbnail images with caption - 06 Jun 2021 04:06
MyBlogLog recent visitors - 06 Jun 2021 04:03
Sorted-ListPages-List - 06 Jun 2021 03:46
Teachertube - 06 Jun 2021 03:45
MP3 Player - 06 Jun 2021 03:45
Include Any Page - 06 Jun 2021 03:20
New Wikidot Twitter Widget..CSS3 Style! - 06 Jun 2021 03:18
Put comments in the editor that won't show - 06 Jun 2021 03:15
Babelfish Translation - 06 Jun 2021 03:14
Fancy HR Dividers - 07 Apr 2021 06:23
Fake tags with links - 06 Jan 2021 16:07
Collapsible Text Block - 02 Dec 2020 10:24
Colalt - Multiple Collapsibles - 17 Sep 2020 13:29
URL Title with Slash Redirect - 04 Jan 2018 11:32
Html5player - 11 Jul 2017 04:05
Mp3 and video player - 21 Oct 2016 12:48
Mail to all moderators - 10 Jun 2015 09:34
Carousel - 24 May 2015 01:18
Modal Image - 01 May 2015 17:20
Todo List with Data Forms - 30 Apr 2015 14:59
Countdown timer - 22 Dec 2014 08:31
Html(embed) code opening in new window/tab - 29 Oct 2014 09:05
Todo List - 18 Aug 2014 15:28
Bootstrap Image Box - 19 Jul 2014 01:27
Extended NewPage Module - 15 Jul 2014 15:08
Facebook Button - 27 Dec 2013 15:03
Togglecheck - 17 Dec 2013 20:27
Alternative Specific Users Only - 11 Dec 2013 18:04
Image Box - 10 Dec 2013 03:14
Specific Users Only Include - 24 Jul 2013 06:16
Toggle Tag - 19 Jul 2013 11:13
Pretty Tables - 29 May 2013 06:14
Custom Page Title - 29 May 2013 06:04
Hide Tags - 14 Feb 2013 21:35
Multicolumn Layout - 17 Dec 2012 19:51
404 (Page does not exist) Redirect - 20 Nov 2012 11:40
Custom HTML Blocks - 25 Oct 2012 11:30
Per-User CSS - 07 Aug 2012 04:05
iframe Redirect - 30 Jul 2012 22:41
Plurality Checker - 16 Jul 2012 03:21
Identi.ca feeds on your site - 12 Jun 2012 18:51
Genuinely Random Link Generator - 31 May 2012 16:28
Mini Chat Area - 15 May 2012 12:04
Chatbox - 26 Mar 2012 11:07
Google +1 Button - 19 Mar 2012 19:40
Per Category CSS Module - 06 Mar 2012 03:38
Advanced Search - 25 Feb 2012 12:29
This Site Last Updated... - 16 Feb 2012 02:37
Zoho Writer - 16 Feb 2012 01:57
Zoho Sheet - 16 Feb 2012 01:56
Zoho Show - 16 Feb 2012 01:55
Zoho Polls - 16 Feb 2012 01:53
Yahoo! WebPlayer - 16 Feb 2012 01:53
WoW Tooltips - 16 Feb 2012 01:52
Wishlist - 16 Feb 2012 01:52
Widgetbox Panel - 16 Feb 2012 01:52
Welcome - 16 Feb 2012 01:52
Voicethread - 16 Feb 2012 01:51
Vimeo - 16 Feb 2012 01:51
Video Quiz - 16 Feb 2012 01:51
Video Player - 16 Feb 2012 01:50
Video from Revver - 16 Feb 2012 01:50
Using Divs - 16 Feb 2012 01:50
Tweet Button - 16 Feb 2012 01:49
Top Nav Menu with ListPages - 16 Feb 2012 01:48
TOC's from many pages - 16 Feb 2012 01:47
Thumbnail page list using ListPages - 16 Feb 2012 01:47
Tags as variables - 16 Feb 2012 01:46
Tabs - 16 Feb 2012 01:45
Table Alterations - 16 Feb 2012 01:45
Syntax Highlighter - 16 Feb 2012 01:45
Rate this solution
If you think this solution is useful — rate it up!
How to change its size
欢迎访问我的个人主页、博客和维基。
莫谈纷争多扰攘,心宽自可化桑田