Introduction

In this blog, we will make a simple timer. We will use three files, .aspx page, CSS and Jquery
Step 1: ASPX page
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="textBoxClickStartTimer.Index" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html>
  4. <head>
  5. <link href="style/flipclock.css" rel="stylesheet" />
  6. <style>
  7. .clock
  8. {
  9. display: none;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <form runat="server">
  15. <table>
  16. <tr>
  17. <td>
  18. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  19. </td>
  20. <td>
  21. <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
  22. </td>
  23. <td>
  24. <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
  25. </td>
  26. <td>
  27. <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
  28. </td>
  29. <td>
  30. <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
  31. </td>
  32. <td>
  33. <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
  34. </td>
  35. <td>
  36. <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
  37. </td>
  38. </tr>
  39. <tr>
  40. <td>
  41. <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
  42. </td>
  43. <td>
  44. <asp:TextBox ID="TextBox9" runat="server"></asp:TextBox>
  45. </td>
  46. <td>
  47. <asp:TextBox ID="TextBox10" runat="server"></asp:TextBox>
  48. </td>
  49. <td>
  50. <asp:TextBox ID="TextBox11" runat="server"></asp:TextBox>
  51. </td>
  52. <td>
  53. <asp:TextBox ID="TextBox12" runat="server"></asp:TextBox>
  54. </td>
  55. <td>
  56. <asp:TextBox ID="TextBox13" runat="server"></asp:TextBox>
  57. </td>
  58. <td>
  59. <asp:TextBox ID="TextBox14" runat="server"></asp:TextBox>
  60. </td>
  61. </tr>
  62. <tr>
  63. <td>
  64. <asp:TextBox ID="TextBox15" runat="server"></asp:TextBox>
  65. </td>
  66. <td>
  67. <asp:TextBox ID="TextBox16" runat="server"></asp:TextBox>
  68. </td>
  69. <td>
  70. <asp:TextBox ID="TextBox17" runat="server"></asp:TextBox>
  71. </td>
  72. <td>
  73. <asp:TextBox ID="TextBox18" runat="server"></asp:TextBox>
  74. </td>
  75. <td>
  76. <asp:TextBox ID="TextBox19" runat="server"></asp:TextBox>
  77. </td>
  78. <td>
  79. <asp:TextBox ID="TextBox20" runat="server"></asp:TextBox>
  80. </td>
  81. <td>
  82. <asp:TextBox ID="TextBox21" runat="server"></asp:TextBox>
  83. </td>
  84. </tr>
  85. </table>
  86. <div class="clock" style="margin: 2em;"></div>
  87. <div class="message"></div>
  88. </form>
  89. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
  90. <script src="script/flipclock.min.js"></script>
  91. <script type="text/javascript">
  92. var clock;
  93. $(document).ready(function() {
  94. clock = $('.clock').FlipClock(0, {
  95. clockFace: 'MinuteCounter',
  96. autoStart: false
  97. });
  98. $("input:text").focus(function() {
  99. $('.clock').css("display", "inline");
  100. clock.start();
  101. });
  102. $("input:text").focusout(function() {
  103. clock.stop();
  104. if (confirm("Do you wanna reset clock?") == true) {
  105. clock.setTime(0);
  106. }
  107. $('.clock').css("display", "none");
  108. });
  109. });
  110. </script>
  111. </body>
  112. </html>
Step 2: CSS
Now in CSS, we have some tasks:
Create a "flipclock.css" file
  1. .flip-clock-wrapper * {
  2. -webkit-box-sizing: border-box;
  3. -moz-box-sizing: border-box;
  4. -ms-box-sizing: border-box;
  5. -o-box-sizing: border-box;
  6. box-sizing: border-box;
  7. -webkit-backface-visibility: hidden;
  8. -moz-backface-visibility: hidden;
  9. -ms-backface-visibility: hidden;
  10. -o-backface-visibility: hidden;
  11. backface-visibility: hidden;
  12. }
  13. .flip-clock-wrapper a {
  14. cursor: pointer;
  15. text-decoration: none;
  16. color: #ccc;
  17. }
  18. .flip-clock-wrapper a:hover {
  19. color: #fff;
  20. }
  21. .flip-clock-wrapper ul {
  22. list-style: none;
  23. }
  24. .flip-clock-wrapper.clearfix:before,
  25. .flip-clock-wrapper.clearfix:after {
  26. content: " ";
  27. display: table;
  28. }
  29. .flip-clock-wrapper.clearfix:after {
  30. clear: both;
  31. }
  32. .flip-clock-wrapper.clearfix {
  33. *zoom: 1;
  34. }
  35. /* Main */
  36. .flip-clock-wrapper {
  37. font: normal 11px "Helvetica Neue", Helvetica, sans-serif;
  38. -webkit-user-select: none;
  39. }
  40. .flip-clock-meridium {
  41. background: none !important;
  42. box-shadow: 0 0 0 !important;
  43. font-size: 36px !important;
  44. }
  45. .flip-clock-meridium a {
  46. color: #313333;
  47. }
  48. .flip-clock-wrapper {
  49. text-align: center;
  50. position: relative;
  51. width: 100%;
  52. margin: 1em;
  53. }
  54. .flip-clock-wrapper:before,
  55. .flip-clock-wrapper:after {
  56. content: " ";
  57. /* 1 */
  58. display: table;
  59. /* 2 */
  60. }
  61. .flip-clock-wrapper:after {
  62. clear: both;
  63. }
  64. /* Skeleton */
  65. .flip-clock-wrapper ul {
  66. position: relative;
  67. float: left;
  68. margin: 5px;
  69. width: 15px;
  70. height: 45px;
  71. font-size: 80px;
  72. font-weight: bold;
  73. line-height: 46px;
  74. border-radius: 6px;
  75. background: #000;
  76. }
  77. .flip-clock-wrapper ul li {
  78. z-index: 1;
  79. position: absolute;
  80. left: 0;
  81. top: 0;
  82. width: 100%;
  83. height: 100%;
  84. line-height: 46px;
  85. text-decoration: none !important;
  86. }
  87. .flip-clock-wrapper ul li:first-child {
  88. z-index: 2;
  89. }
  90. .flip-clock-wrapper ul li a {
  91. display: block;
  92. height: 100%;
  93. -webkit-perspective: 200px;
  94. -moz-perspective: 200px;
  95. perspective: 200px;
  96. margin: 0 !important;
  97. overflow: visible !important;
  98. cursor: default !important;
  99. }
  100. .flip-clock-wrapper ul li a div {
  101. z-index: 1;
  102. position: absolute;
  103. left: 0;
  104. width: 100%;
  105. height: 50%;
  106. font-size: 80px;
  107. overflow: hidden;
  108. outline: 1px solid transparent;
  109. }
  110. .flip-clock-wrapper ul li a div .shadow {
  111. position: absolute;
  112. width: 100%;
  113. height: 100%;
  114. z-index: 2;
  115. }
  116. .flip-clock-wrapper ul li a div.up {
  117. -webkit-transform-origin: 50% 100%;
  118. -moz-transform-origin: 50% 100%;
  119. -ms-transform-origin: 50% 100%;
  120. -o-transform-origin: 50% 100%;
  121. transform-origin: 50% 100%;
  122. top: 0;
  123. }
  124. .flip-clock-wrapper ul li a div.up:after {
  125. content: "";
  126. position: absolute;
  127. top: 22px;
  128. left: 0;
  129. z-index: 5;
  130. width: 100%;
  131. height: 3px;
  132. background-color: #000;
  133. background-color: rgba(0, 0, 0, 0.4);
  134. }
  135. .flip-clock-wrapper ul li a div.down {
  136. -webkit-transform-origin: 50% 0;
  137. -moz-transform-origin: 50% 0;
  138. -ms-transform-origin: 50% 0;
  139. -o-transform-origin: 50% 0;
  140. transform-origin: 50% 0;
  141. bottom: 0;
  142. border-bottom-left-radius: 6px;
  143. border-bottom-right-radius: 6px;
  144. }
  145. .flip-clock-wrapper ul li a div div.inn {
  146. position: absolute;
  147. left: 0;
  148. z-index: 1;
  149. width: 100%;
  150. height: 200%;
  151. color: #ccc;
  152. text-shadow: 0 1px 2px #000;
  153. text-align: center;
  154. background-color: #333;
  155. border-radius: 6px;
  156. font-size: 40px;
  157. }
  158. .flip-clock-wrapper ul li a div.up div.inn {
  159. top: 0;
  160. }
  161. .flip-clock-wrapper ul li a div.down div.inn {
  162. bottom: 0;
  163. }
  164. /* PLAY */
  165. .flip-clock-wrapper ul.play li.flip-clock-before {
  166. z-index: 3;
  167. }
  168. .flip-clock-wrapper .flip {
  169. box-shadow: 0 2px 5px rgba(0, 0, 0, 0.7);
  170. }
  171. .flip-clock-wrapper ul.play li.flip-clock-active {
  172. -webkit-animation: asd 0.5s 0.5s linear both;
  173. -moz-animation: asd 0.5s 0.5s linear both;
  174. animation: asd 0.5s 0.5s linear both;
  175. z-index: 5;
  176. }
  177. .flip-clock-divider {
  178. float: left;
  179. display: inline-block;
  180. position: relative;
  181. width: 20px;
  182. height: 50px;
  183. }
  184. .flip-clock-divider:first-child {
  185. width: 0;
  186. }
  187. .flip-clock-dot {
  188. display: block;
  189. background: #323434;
  190. width: 10px;
  191. height: 10px;
  192. position: absolute;
  193. border-radius: 50%;
  194. box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
  195. left: 5px;
  196. }
  197. .flip-clock-divider .flip-clock-label {
  198. position: absolute;
  199. top: -1.5em;
  200. right: -86px;
  201. color: black;
  202. text-shadow: none;
  203. }
  204. .flip-clock-divider.minutes .flip-clock-label {
  205. right: -88px;
  206. }
  207. .flip-clock-divider.seconds .flip-clock-label {
  208. right: -91px;
  209. }
  210. .flip-clock-dot.top {
  211. top: 30px;
  212. }
  213. .flip-clock-dot.bottom {
  214. bottom: 30px;
  215. }
  216. @-webkit-keyframes asd {
  217. 0% {
  218. z-index: 2;
  219. }
  220. 20% {
  221. z-index: 4;
  222. }
  223. 100% {
  224. z-index: 4;
  225. }
  226. }
  227. @-moz-keyframes asd {
  228. 0% {
  229. z-index: 2;
  230. }
  231. 20% {
  232. z-index: 4;
  233. }
  234. 100% {
  235. z-index: 4;
  236. }
  237. }
  238. @-o-keyframes asd {
  239. 0% {
  240. z-index: 2;
  241. }
  242. 20% {
  243. z-index: 4;
  244. }
  245. 100% {
  246. z-index: 4;
  247. }
  248. }
  249. @keyframes asd {
  250. 0% {
  251. z-index: 2;
  252. }
  253. 20% {
  254. z-index: 4;
  255. }
  256. 100% {
  257. z-index: 4;
  258. }
  259. }
  260. .flip-clock-wrapper ul.play li.flip-clock-active .down {
  261. z-index: 2;
  262. -webkit-animation: turn 0.5s 0.5s linear both;
  263. -moz-animation: turn 0.5s 0.5s linear both;
  264. animation: turn 0.5s 0.5s linear both;
  265. }
  266. @-webkit-keyframes turn {
  267. 0% {
  268. -webkit-transform: rotateX(90deg);
  269. }
  270. 100% {
  271. -webkit-transform: rotateX(0deg);
  272. }
  273. }
  274. @-moz-keyframes turn {
  275. 0% {
  276. -moz-transform: rotateX(90deg);
  277. }
  278. 100% {
  279. -moz-transform: rotateX(0deg);
  280. }
  281. }
  282. @-o-keyframes turn {
  283. 0% {
  284. -o-transform: rotateX(90deg);
  285. }
  286. 100% {
  287. -o-transform: rotateX(0deg);
  288. }
  289. }
  290. @keyframes turn {
  291. 0% {
  292. transform: rotateX(90deg);
  293. }
  294. 100% {
  295. transform: rotateX(0deg);
  296. }
  297. }
  298. .flip-clock-wrapper ul.play li.flip-clock-before .up {
  299. z-index: 2;
  300. -webkit-animation: turn2 0.5s linear both;
  301. -moz-animation: turn2 0.5s linear both;
  302. animation: turn2 0.5s linear both;
  303. }
  304. @-webkit-keyframes turn2 {
  305. 0% {
  306. -webkit-transform: rotateX(0deg);
  307. }
  308. 100% {
  309. -webkit-transform: rotateX(-90deg);
  310. }
  311. }
  312. @-moz-keyframes turn2 {
  313. 0% {
  314. -moz-transform: rotateX(0deg);
  315. }
  316. 100% {
  317. -moz-transform: rotateX(-90deg);
  318. }
  319. }
  320. @-o-keyframes turn2 {
  321. 0% {
  322. -o-transform: rotateX(0deg);
  323. }
  324. 100% {
  325. -o-transform: rotateX(-90deg);
  326. }
  327. }
  328. @keyframes turn2 {
  329. 0% {
  330. transform: rotateX(0deg);
  331. }
  332. 100% {
  333. transform: rotateX(-90deg);
  334. }
  335. }
  336. .flip-clock-wrapper ul li.flip-clock-active {
  337. z-index: 3;
  338. }
  339. /* SHADOW */
  340. .flip-clock-wrapper ul.play li.flip-clock-before .up .shadow {
  341. background: -moz-linear-gradient(top, rgba(0, 0, 0, 0.1) 0%, black 100%);
  342. background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(0, 0, 0, 0.1)), color-stop(100%, black));
  343. background: linear, top, rgba(0, 0, 0, 0.1) 0%, black 100%;
  344. background: -o-linear-gradient(top, rgba(0, 0, 0, 0.1) 0%, black 100%);
  345. background: -ms-linear-gradient(top, rgba(0, 0, 0, 0.1) 0%, black 100%);
  346. background: linear, to bottom, rgba(0, 0, 0, 0.1) 0%, black 100%;
  347. -webkit-animation: show 0.5s linear both;
  348. -moz-animation: show 0.5s linear both;
  349. animation: show 0.5s linear both;
  350. }
  351. .flip-clock-wrapper ul.play li.flip-clock-active .up .shadow {
  352. background: -moz-linear-gradient(top, rgba(0, 0, 0, 0.1) 0%, black 100%);
  353. background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(0, 0, 0, 0.1)), color-stop(100%, black));
  354. background: linear, top, rgba(0, 0, 0, 0.1) 0%, black 100%;
  355. background: -o-linear-gradient(top, rgba(0, 0, 0, 0.1) 0%, black 100%);
  356. background: -ms-linear-gradient(top, rgba(0, 0, 0, 0.1) 0%, black 100%);
  357. background: linear, to bottom, rgba(0, 0, 0, 0.1) 0%, black 100%;
  358. -webkit-animation: hide 0.5s 0.3s linear both;
  359. -moz-animation: hide 0.5s 0.3s linear both;
  360. animation: hide 0.5s 0.3s linear both;
  361. }
  362. /*DOWN*/
  363. .flip-clock-wrapper ul.play li.flip-clock-before .down .shadow {
  364. background: -moz-linear-gradient(top, black 0%, rgba(0, 0, 0, 0.1) 100%);
  365. background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, black), color-stop(100%, rgba(0, 0, 0, 0.1)));
  366. background: linear, top, black 0%, rgba(0, 0, 0, 0.1) 100%;
  367. background: -o-linear-gradient(top, black 0%, rgba(0, 0, 0, 0.1) 100%);
  368. background: -ms-linear-gradient(top, black 0%, rgba(0, 0, 0, 0.1) 100%);
  369. background: linear, to bottom, black 0%, rgba(0, 0, 0, 0.1) 100%;
  370. -webkit-animation: show 0.5s linear both;
  371. -moz-animation: show 0.5s linear both;
  372. animation: show 0.5s linear both;
  373. }
  374. .flip-clock-wrapper ul.play li.flip-clock-active .down .shadow {
  375. background: -moz-linear-gradient(top, black 0%, rgba(0, 0, 0, 0.1) 100%);
  376. background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, black), color-stop(100%, rgba(0, 0, 0, 0.1)));
  377. background: linear, top, black 0%, rgba(0, 0, 0, 0.1) 100%;
  378. background: -o-linear-gradient(top, black 0%, rgba(0, 0, 0, 0.1) 100%);
  379. background: -ms-linear-gradient(top, black 0%, rgba(0, 0, 0, 0.1) 100%);
  380. background: linear, to bottom, black 0%, rgba(0, 0, 0, 0.1) 100%;
  381. -webkit-animation: hide 0.5s 0.3s linear both;
  382. -moz-animation: hide 0.5s 0.3s linear both;
  383. animation: hide 0.5s 0.2s linear both;
  384. }
  385. @-webkit-keyframes show {
  386. 0% {
  387. opacity: 0;
  388. }
  389. 100% {
  390. opacity: 1;
  391. }
  392. }
  393. @-moz-keyframes show {
  394. 0% {
  395. opacity: 0;
  396. }
  397. 100% {
  398. opacity: 1;
  399. }
  400. }
  401. @-o-keyframes show {
  402. 0% {
  403. opacity: 0;
  404. }
  405. 100% {
  406. opacity: 1;
  407. }
  408. }
  409. @keyframes show {
  410. 0% {
  411. opacity: 0;
  412. }
  413. 100% {
  414. opacity: 1;
  415. }
  416. }
  417. @-webkit-keyframes hide {
  418. 0% {
  419. opacity: 1;
  420. }
  421. 100% {
  422. opacity: 0;
  423. }
  424. }
  425. @-moz-keyframes hide {
  426. 0% {
  427. opacity: 1;
  428. }
  429. 100% {
  430. opacity: 0;
  431. }
  432. }
  433. @-o-keyframes hide {
  434. 0% {
  435. opacity: 1;
  436. }
  437. 100% {
  438. opacity: 0;
  439. }
  440. }
  441. @keyframes hide {
  442. 0% {
  443. opacity: 1;
  444. }
  445. 100% {
  446. opacity: 0;
  447. }
  448. }
NOTE: if you want to change the height of timer then change in these classes.
1. flip-clock-wrapper ul
change width and height in 1:3 ratio also you should change 'line-height'
2. flip-clock-wrapper ul li a div.up:after -->change top
3. flip-clock-divider --> change height
Step 3: Javascript
Add 'flipclock.min.js' in aspx page.
Here we have some callback function that you can use to can timer properties.
  • Destroy: This callback is triggered when the timer is destroyed.
  • Create: This callback is triggered when the clock face is created.
  • init: This callback is triggered when the FlipClock object is initialized.
  • interval: This callback is triggered with each interval of the time.r
  • start: This callback is triggered when the clock is started.
  • stop: This callback is triggered when the clock is stopped.
  • reset: This callback is triggered when the timer has been reset.
Methods
start() :- This method will start the clock just call the .start() method on an FlipClock object.
  1. clock.start(function() { // this (optional) callback will fire each time the clock flips });
stop() :- This method will stop the clock just call the .stop() method on an FlipClock object.
  1. clock.stop(function() { // this (optional) callback will fire after the clock stops });
setTime(): This method will set the clock time after it has been instantiated just call the .setTime() method on an FlipClock object.
  1. clock.setTime(3600);
setCountdown(): This method will change the clock from counting up or down.
  1. clock.setCountdown(true);
getTime(): To get the clock time after it has been instantiated just call the .getTime() method on an FlipClock object.
  1. var time = clock.getTime(); // Returns the FlipClock.Time object