Hear the timer after perhaps we think only in JS can be achieved, in fact, this idea in you do not know there are HTML5 circumstances can be set up, the following for you to introduce the next HTML5 is how to implement the timer, interested friends do not miss
Html:
Copy CodeThe code is as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<!--Always Force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the htaccess-->
<meta http-equiv= "x-ua-compatible" content= "ie=edge,chrome=1" >
<TITLE>HTML5 Timer for Work-relax balance</title>
<meta name= "description" content= "" >
<meta name= "Author" content= "Kevin" >
<meta name= "viewport" content= "width=device-width; initial-scale=1.0 ">
<!--Replace Favicon.ico & apple-touch-icon.png in the root your domain and delete these references-->
<link rel= "shortcut icon" href= "/favicon.ico"/>
<link rel= "Apple-touch-icon" href= "/apple-touch-icon.png"/>
<link rel= "stylesheet" type= "Text/css" href= "Css/style.css" >
<script>
Countdownseconds = 60;
var handle = null;
Window load
function Onloadwindow () {
Acanvas = document.getElementById ("Countdowncanvas");
Context = Acanvas.getcontext ("2d");
var canvastext = "Press to Start ...";
var xpos = ACANVAS.WIDTH/2;
var yPos = ACANVAS.HEIGHT/2;
Context.font = "12pt Century gothic";
Context.fillstyle = "#008000;";
context.textalign = "center";
Context.textbaseline = "Middle";
Context.filltext (Canvastext, xpos, YPos);
}
function Updatecanvas (thecontext, width, height) {
if (Countdownseconds < 0) {
Clearinterval (handle);
handle = NULL;
Alert ("Hey, Time is up!");
return 0;
}
Minstr = Math.floor (COUNTDOWNSECONDS/60);
SECSTR = countdownseconds% 60;
if (Minstr < 10) {
Minstr = "0" + minstr;
}
if (Secstr < 10) {
Secstr = "0" + secstr;
}
Context.clearrect (0, 0, width, height);
Context.font = "24pt Century gothic";
Context.filltext (Minstr + ":" + secstr, WIDTH/2, HEIGHT/2);
countdownseconds--;
}
function Startworkcountdown () {
if (handle!= null) {
Clearinterval (handle);
}
Countdownseconds = document.getElementById ("Workintervalinput"). Value * 60;
Timedisplaycanvas = document.getElementById ("Countdowncanvas");
TIMEDISPLAYCONTEXT2D = Timedisplaycanvas.getcontext ("2d");
Updatecanvas (timedisplaycontext2d, Timedisplaycanvas.width, timedisplaycanvas.height);
Handle = SetInterval (function () {
Updatecanvas (timedisplaycontext2d, Timedisplaycanvas.width, timedisplaycanvas.height);
}, 1000);
}
function Startrestcountdown () {
if (handle!= null) {
Clearinterval (handle);
}
Countdownseconds = document.getElementById ("Restintervalinput"). Value * 60;
Timedisplaycanvas = document.getElementById ("Countdowncanvas");
TIMEDISPLAYCONTEXT2D = Timedisplaycanvas.getcontext ("2d");
Updatecanvas (timedisplaycontext2d, Timedisplaycanvas.width, timedisplaycanvas.height);
Handle = SetInterval (function () {
Updatecanvas (timedisplaycontext2d, Timedisplaycanvas.width, timedisplaycanvas.height);
}, 1000);
}
</script>
<body onload= "Onloadwindow ()" >
<div align= "center" >
Please choose the work interval:
<input name= "Workintervalinput" id= "Workintervalinput" type= "number" value= "" min= "" max= "" "step=" 5 "/>
Minutes
Please choose the rest interval:
<input name= "Restintervalinput" id= "Restintervalinput" type= "number" value= "5" min= "3" max= "Ten" step= "1"/>
Minutes
<canvas id= "Countdowncanvas" width= "height= style=" border:2px "solid black" >
This is a canvas
</canvas>
<button onclick= "Startworkcountdown ()" >
Work Hard
</button>
<button onclick= "Startrestcountdown ()" >
Take A Break
</button>
<footer>
<p>
© Copyright Reserved
</p>
</footer>
</div>
</body>
CSS3:
Copy CodeThe code is as follows:
/*
* Html5✰boilerplate
*
* What follows is the result of much of the cross-browser styling.
* Credit left inline and a to Nicolas Gallagher, Jonathan Neal,
* Kroc Camen, and the h5bp Dev community and team.
*
* Detailed information about this CSS:H5BP.COM/CSS
*
* ==|== Normalize ==========================================================
*/
/* =============================================================================
HTML5 Display Definitions
========================================================================== */
Article, aside, details, figcaption, figure, Footer, header, Hgroup, nav, section {display:block;}
Header {text-shadow: #220000 0px 0px 10px 10px;}
Audio, canvas, video {display:inline-block; *display:inline; *zoom:1;}
Audio:not ([controls]) {Display:none;}
[Hidden] {Display:none;}
/* =============================================================================
Base
========================================================================== */
/*
* 1. Correct text resizing oddly in IE6/7 as Body font-size is set using EM units
* 2. Force Vertical ScrollBar in Non-ie
* 3. Prevent IOS text Size adjust on device orientation change, without disabling user zoom:h5bp.com/g
*/
HTML {font-size:100%; overflow-y: scroll;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;}
body {margin:0; font-size:24px; line-height:1.231;}
Body, button, input, select, textarea {font-family: "Century Gothic"; Color: #008000}
/*
* Remove Text-shadow in selection highlight:h5bp.com/i
* These selection declarations have to be separate
* Also:hot pink! (or customize the background color to match your)
*/
::-moz-selection {background: #fe57a1; color: #fff; text-shadow:none;}
:: Selection {background: #fe57a1; color: #fff; text-shadow:none;}
/* =============================================================================
Links
========================================================================== */
A {color: #00e;}
a:visited {color: #551a8b;}
a:hover {color: #06e;}
A:focus {Outline:thin dotted;}
/* Improve readability when focused and hovered at all browsers:h5bp.com/h * *
A:hover, a:active {outline:0;}
/* =============================================================================
Typography
========================================================================== */
Abbr[title] {border-bottom:1px dotted;}
B, strong {font-weight:bold;}
blockquote {margin:1em 40px;}
DFN {font-style:italic;}
hr {display:block; height:1px; border:0 border-top:1px solid #ccc; margin:1em 0; padding:0;}
INS {background: #ff9; color: #000; text-decoration:none;}
Mark {background: #ff0; color: #000; font-style:italic; font-weight:bold;}
/* Redeclare monospace Font family:h5bp.com/j * *
Pre, code, KBD, Samp {font-family:monospace, monospace; _font-family: ' Courier New ', monospace; font-size:1em;}
/* Improve readability of pre-formatted text in all browsers * *
Pre {white-space:pre; white-space:pre-wrap; word-wrap:break-word;}
Q {quotes:none;}
Q:before, Q:after {content: ""; Content:none; }
small {font-size:85%;}
/* Position subscript and superscript content without affecting line-height:h5bp.com/k * *
Sub, sup {font-size:75%; line-height:0; position:relative; vertical-align:baseline;}
sup {top: -0.5em;}
Sub {bottom: -0.25em;}
/* =============================================================================
Lists
========================================================================== */
UL, ol {margin:1em 0; padding:0 0 0 40px;}
DD {margin:0 0 0 40px;}
Nav ul, nav ol {list-style:none; list-style-image:none; margin:0; padding:0;}
/* =============================================================================
Embedded Content
========================================================================== */
/*
* 1. Improve image quality when scaled in ie7:h5bp.com/d
* 2. Remove the gap between images and borders on image containers:h5bp.com/e
*/
img {border:0;-ms-interpolation-mode:bicubic; vertical-align:middle;}
/*
* Correct overflow not hidden in IE9
*/
Svg:not (: root) {Overflow:hidden;}
/* =============================================================================
Figures
========================================================================== */
Figure {margin:0;}
/* =============================================================================
Forms
========================================================================== */
form {margin:0;}
fieldset {border:0; margin:0; padding:0;}
/* indicate that ' label ' would shift focus to the associated form element */
label {Cursor:pointer;}
/*
* 1. Correct color not inheriting in IE6/7/8/9
* 2. Correct alignment displayed oddly in IE6/7
*/
Legend {border:0; *margin-left: -7px; padding:0;}
/*
* 1. Correct font-size not inheriting in all browsers
* 2. Remove margins in FF3/4 S5 Chrome
* 3. Define Consistent vertical alignment display in all browsers
*/
button, input, select, textarea {font-size:100%; margin:0; vertical-align:baseline; *vertical-align:middle;}
/*
* 1. Define Line-height as normal to match FF3/4 (set using!important in the UA stylesheet)
* 2. Correct inner spacing displayed oddly in IE6/7
*/
button, input {line-height:normal; *overflow:visible;}
/*
* Reintroduce inner spacing in ' table ' to avoid overlap and whitespace issues in IE6/7
*/
Table button, table input {*overflow:auto;}
/*
* 1. Display hand cursor for clickable form elements
* 2. Allow styling of clickable form elements in IOS
*/
button, input[type= "button"], input[type= "reset"], input[type= "Submit"] {cursor:pointer;-webkit-appearance:button;}
/*
* Consistent box sizing and appearance
*/
Input[type= "checkbox"], input[type= "Radio"] {Box-sizing:border-box;}
Input[type= "Search"] {-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box; Box-sizing:content-box; }
Input[type= "Search"]::-webkit-search-decoration {-webkit-appearance:none;}
/*
* Remove inner padding and border in FF3/4: h5bp.com/l
*/
Button::-moz-focus-inner, Input::-moz-focus-inner {border:0; padding:0;}
/*
* 1. Remove default vertical scrollbar in IE6/7/8/9
* 2. Allow only vertical resizing
*/
textarea {overflow:auto; vertical-align:top; resize:vertical;}
/* Colors for form validity * *
Input:valid, Textarea:valid {}
Input:invalid, Textarea:invalid {background-color: #f0dddd;}
/* =============================================================================
Tables
========================================================================== */
Table {border-collapse:collapse; border-spacing:0;}
td {Vertical-align:top;}
/* ==|== Primary styles =====================================================
Author:
========================================================================== */
/* ==|== non-semantic helper Classes ========================================
Please define your styles before this section.
========================================================================== */
/* for Image replacement * *
. ir {display:block; border:0; text-indent: -999em; overflow:hidden; background-color:transparent; Background-repeat: No-repeat; Text-align:left; direction:ltr; }
. ir br {display:none;}
/* Hide from both screenreaders and browsers:h5bp.com/u * *
. hidden {display:none!important; visibility:hidden;}
/* Hide only visually, but have it available for screenreaders:h5bp.com/v * *
. visuallyhidden {border:0; Clip:rect (0 0 0 0); height:1px; margin: -1px; overflow:hidden; padding:0 Ute width:1px; }
/* Extends the Visuallyhidden class to allow the element to is focusable when navigated to via the keyboard:h5bp.com/p * /
. visuallyhidden.focusable:active, Visuallyhidden.focusable:focus {clip:auto; height:auto; margin:0; overflow: Visible position:static; Width:auto; }
/* Hide visually and from Screenreaders, but maintain layout * *
. Invisible {Visibility:hidden}
/* Contain floats:h5bp.com/q * *
. Clearfix:before,. Clearfix:after {content: ""; display:table; }
. clearfix:after {Clear:both}
. clearfix {Zoom:1}
/* ==|== Media queries ======================================================
Placeholder Media Queries for responsive.
These override the primary (' mobile a ') styles
Modify as content requires.
========================================================================== */
@media only screen and (min-width:480px) {
/* Style adjustments for viewports 480px *
}
@media only screen and (min-width:768px) {
/* Style adjustments for viewports 768px *
}
/* ==|== Print Styles =======================================================
Print styles.
inlined to avoid required HTTP connection:h5bp.com/r
========================================================================== */
@media Print {
* {background:transparent!important; color:black!important text-shadow:none!important filter:none;!important -filter:none!important; }/* Black Prints faster:h5bp.com/s * *
A, a:visited {text-decoration:underline;}
A[href]:after {content: "(" attr (HREF) ")";}
Abbr[title]:after {content: "(" attr (title) ")";}
. ir A:after, a[href^= "javascript:"]:after, a[href^= "#"]:after {content: "";} /* Don t Show links for images, or javascript/internal links */
Pre, blockquote {border:1px solid #999; page-break-inside:avoid;}
thead {Display:table-header-group}/* h5bp.com/t *
TR, img {page-break-inside:avoid;}
img {max-width:100%!important;}
@page {margin:0.5cm;}
P, H2, H3 {orphans:3; widows:3;}
H2, h3 {page-break-after:avoid;}
}
#startTimer {
Position:inherit
width:75px;
height:20px;
top:35px;
left:25px;
Cursor:pointer
}
#stopTimer {
Position:inherit;
width:75px;
height:20px;
top:10px;
left:25px;
Cursor:pointer
}
#countdownCanvas {
border-radius:25px;
box-shadow:10px 10px 5px #888888;
}